You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

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

  1. ${localize('save')}
  2. ${localize('edit', 'Document')}
  3. ${localize(enum_info('MyType', 'myEnum'))} (optionally surround with sort() 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"}]

Search results for "localize()"

localize()

The localize() function can be used to localize strings and therefor create localized user interfaces. It uses the current locale (see keyword locale) to search for nodes of type Localization in the database. This lookup works in 4 stages. If a Localization object is found (in the order of evaluation), the process is stopped. If no localization is found, the key itself is returned.

  1. find localization with exact match on key, domain and full locale
  2. find localization with exact match on key, NO domain and full locale
  3. find localization with exact match on key, domain and language only
  4. find localization with exact match on key, domain and language only
  5. Restart steps 1-4 with the fallback locale - if defined and active via structr.conf:
    • application.localization.usefallbacklocale = enable/disable use of the fallback locale
    • application.localization.fallbacklocale = the fallback locale

If after step 4 no localization is found, the input parameters are logged if the configuration entry application.localization.logmissing in structr.conf is enabled.

localize(key [, domain])
localize(keys [, domain])

Deployment Format

folder / filedescription
componentsContains the shared components of the pages editor of Structr.
filesContains all files out of Sturctr’s virtual filesystem. Folders and files in the virtual filesystem are not being exported by default. If you want to include a folder or file into the export you have to set the flag includeInFrontendExport on each file or folder. Each file or folder will inherit this flag from its parent folder.
mail-templatesContains the mail-templates.
modulesContains the application configuration and definition of additional modules of Structr e.g. the flow engine.
pagesContains the created pages in the pages editor of Structr.
schemaContains the schema definition and code entered in the schema and code section of the Structr UI.
securityContains the resource access grants defined in the security section of the Structr UI.
templatesContains all template elements of the pages editor of Structr.
application-configuration-data.jsonContains the configured schema layouts of Structr’s schema editor.
components.jsonContains the settings e.g. visiblity flags, contentType or uuid for each file in the components folder of the export.
deploy.confContains information about the Structr system that created the export of the application.
files.jsonContains the settings e.g. visiblity flags, contentType or uuid for each file in the files folder of the export.
localizations.jsonContains the localizations that where created in the localizations section of the Structr UI and that can be used in server side scripting with the localize() function of Structr.
mail-templates.jsonContains the settings e.g. visiblity flags, locale or uuid for each file in the mail-templates folder of the export.
pages.jsonContains the settings e.g. visiblity flags, contentType or uuid for each file in the pages folder of the export.
pre-deploy.confScript that is run before deployment import. Use this to create users who are granted access to nodes in the export files.
post-deploy.confScript that is run after deployment import. Can be used to start any tasks which are necessary after import.
sites.jsonContains sites that are configured in the pages section of the Structr UI.
templates.jsonContains the settings e.g. visiblity flags, contentType or uuid for each file in the templates folder of the export.
widget.jsonContains the widgets that were created in the pages section of the Structr UI.