localize()
Usage
localize(key, domain)
localize(key)
localize(list) (*)
localize(list, domain) (*)
Description
Returns a localized string for the given key, using the locale setting of the current user, with an optional domain. This method can be used to localize strings in a Structr-based web application. If no localization was found for the given (key, domain) tuple, but there is a localization for the given key without a domain, this localization is returned.
If no localized string is found for the full locale string (e.g. en_US
), the localize()
function looks for a localized string for the language part of the locale setting (in this case: en
). If this yields no localized string, the key itself is returned. Using the configuration key application.localization.logMissing
these requested but non-existing localized strings can be logged.
Localization in Structr is based on the Localization
entity, which is a built-in type. See Localization for more information on that topic.
(*) Since Structr 2.1 the localize() function also supports a list/array as its first argument. The returned list contains the original value and the localized value in the keys “name” and “localized” (see example 3 for a practical use of this feature)
Example
${localize('save')}
${localize('edit', 'Document')}
${localize(enum_info('MyType', 'myEnum'))}
(optionally surround withsort()
to have the list sorted by localizedName or name)
results in
Save
Edit this document
[{name: "enumValue1", localizedName:"Localized Enum Value 1"}, {name: "enumValue2", localizedName:"Localized Enum Value 2"}, {name: "enumValue3", localizedName:"Localized Enum Value 3"}]