![]() |
![]() |
![]() |
Cockpit Guide | ![]() |
---|
cockpit.js: Localizationcockpit.js: Localization — Localization and translations |
Cockpit provides a
gettext()
like
API for easy translation of strings.
The current locale language code. This is set based on the
cockpit.locale()
data loaded.
cockpit.locale(po)
Load locale information for a given po
data. The data should
be JSON data in the po2json
format. The data will be loaded globally. If po
data has already been
loaded, then this will extend that loaded data with additional strings. Any identical
translations strings will be replaced with the new strings.
Various methods such as
cockpit.gettext()
make use
of the loaded data.
translated = cockpit.gettext([context], string) var _ = cockpit.gettext var C_ = cockpit.gettext translated = _("string") translated = C_("context", "string")
Lookup string
for translation in the loaded locale data. The translated string will
be returned, or string
will be returned if no such translated string is
present. The context
argument is an optional string used to qualify the
string.
This function can be assigned to a variable called _
(underscore) which
will make your code work with the typical _("string")
syntax.
var N_ = cockpit.noop var NC_ = cockpit.noop
A noop function suitable for assigning to N_
or NC_
so that
gettext scanners will be able to find translatable strings. More specifically this function
returns its last argument.
translated = cockpit.ngettext([context], string1, stringN, number)
Lookup a string appropriate for a pluralization form of the number
.
Various languages have complex pluralization forms that go far between the singular
and plural forms speakers of English are familiar with. If no such translated
string is found then either one of string1
or stringN
is
returned according to simple pluralization rules.
The context
argument is an optional string used to qualify the string.