OPX//77
opx_lib

Lib.Locale

Last updated on

A per-resource translation catalogue formatted with string.format.

Pure. No permission. Each resource has its own catalogue. Formatting uses string.format (%s, %d), not {name} placeholders.

Lib.Locale.Load

Replaces the catalogue. Non-string keys and values are refused.

Lib.Locale.Load(catalogue)

Parameters

  • catalogue: table<key, string>

Returns

  • integer — entries accepted
Example
Lib.Locale.Load({ ['shop.bought'] = 'You bought %d %s.' })

Lib.Locale.Set

Adds or replaces one entry.

Lib.Locale.Set(key, value)

Parameters

  • key: string
  • value: string

Returns

  • boolean — accepted

Lib.Locale.Get

The translation, formatted with any arguments. A missing key answers the key itself; a format that fails answers the key. Never nil.

Lib.Locale.Get(key, ...)

Parameters

  • key: string
  • ...: any

Returns

  • string
Example
Lib.Notify.Show(Lib.Locale.Get('shop.bought', 2, 'water'))

Lib.Locale.Has

Whether a key is in the catalogue.

Lib.Locale.Has(key)

Parameters

  • key: string

Returns

  • boolean

On this page