Current locale

Value resolver – Abstract

Purpose: This returns the dynamic enumeration value of the Locale valid in the current session. For country-specific languages, the reference to the country can be selected or unselected.

images/download/attachments/91135153/image2022-2-10_16-57-28-version-1-modificationdate-1644508648249-api-v2.png

The Current locale value resolver identifies the Locale applicable to the current session. The return value is a value from the relevant dynamic enumeration (Locale).

The Locale without country option defines whether the value resolver for country-specific distinct languages returns their enumeration value or the enumeration value of the global locale to which the applicable language refers.

NOTE

Configuration

The Locale without country option relates to the possibility of defining country-specific versions of a given global locale when defining languages in the dynamic enumeration Locale.

images/download/attachments/91135153/image2022-2-10_16-57-45-version-1-modificationdate-1644508665159-api-v2.png

If the option is not checked (default), then the value resolver returns the dynamic enumeration value for the (country-specific, if applicable) locale in effect in the session, e.g. the language 'German (Switzerland)' (de_CH) or 'English (US)' (en_US).

NOTE◄ The return value with this setting corresponds to the value in the locale property of a Print XML.

images/download/attachments/91135153/image2022-2-10_16-58-11-version-1-modificationdate-1644508691902-api-v2.png

If the option is checked, then the value resolver returns the dynamic enumeration value for the global locale that either applies directly to the session or is referred to by the logged-in country-specific language:

  • If the session uses the country-specific locale 'German (Switzerland)' (de_CH) the return value 'German' (de) would apply, for 'English (US)' (en_US) the value 'English' (en), etc.

  • If the session already uses a global locale, e.g. 'English' (en), this will be returned directly.

Special case:

  • If the session uses a country-specific locale whose internal name (name of the enumeration value) refers to a global locale that is not defined as a global locale, then by default (see Locale, 'Precedence rules') the language 'English' (en) is used for the session and not, for example, the default locale defined in the system. In this special case, the enumeration value for 'English' (en) also appears as the return value of the Current locale value resolver.

Example

An association criteria (see Association criteria) is considered 'passed' if a country-specific locale is used in the current session.

Depending on this association criteria, an Image/Icon element can be displayed or hidden in a form that shows a graphic for the flag of the country 'coded' in the locale (if available).

Runtime example:

images/download/attachments/91135153/image2022-2-10_17-3-26-version-1-modificationdate-1644509006729-api-v2.png

  • The image shows a section of an input form for shipment details, where the Current locale is visualized by flag icons in the header area in addition to a reference in the User of session.

  • In the session shown, the Locale 'English (US)' (en_US) is selected. The right flag symbol (here: USA) should only be visible if a country-specific locale is selected.

NOTE◄ The left flag of the two 'flags' is defined by another section in the Client workflow described only partially below, based on Current locale ('without country'). However, it must be taken into account that the internal name of the Locale 'English' (en) does not correspond to an ISO 3611 alpha2 abbreviation. The output in the runtime example can be obtained by placing a copy of the flag graphic gb.png under the name en.png. Then this assignment (en=gb) can also be used in other contexts. Otherwise, this can be done by replacing the 'language name' en with the country code gb (or any other such as us or au) using Replace text when building the file name.

Configuration:

To detect the selection of a country-specific locale in the context of the current session, a custom association criteria is created and configured as follows:

An Entity property rule is used to compare the return values of the Current locale value resolver with and without selecting the Locale without country option:

  • On the left side of the comparison, the Locale without country option is not checked in the Current locale value resolver. At runtime, the selected Locale is queried, whose enumeration value specifies a 'Locale with country' as appropriate.

  • On the right side of the comparison, the Locale without country option is checked in the Current locale value resolver. Therefore, the Locale without country is queried, and either the enumeration value for the global locale returned as the selected language – and if it does not exist – the default value given by the system: 'English' (en).

  • The selected comparison type Equals is negated (see not (Matcher)), so that the association criteria is considered 'passed' if the left and right resolved values are different.

images/download/attachments/91135153/image2022-2-10_17-5-27-version-1-modificationdate-1644509127393-api-v2.png

A behaviour is added to the form that links the visibility for the Image/Icon element representing the 'country' referenced in the locale to the association criteria shown above:

  • The behaviour shown on the right responds to the Triggering event Form data loaded, which ensures that the visibility of the Image/Icon element when displaying data in the form is controlled 'appropriately' for the session.

  • The Behaviour type Association criterion matched checks whether the association criteria shown above is true or not.

  • In the Actions on "true", a Show element action makes the Target element 'Country code' (the Image/Icon with the second flag) visible if the association criteria is true, i.e. if a country-specific language is selected.

  • In the Actions on "false", a Hide element action makes the Target element 'Country code' (the Image/Icon with the second flag) invisible if the association criteria does not apply, i.e. no country-specific language is selected.

images/download/attachments/91135153/image2022-2-10_17-6-50-version-1-modificationdate-1644509210752-api-v2.png

Depending on the selected locale, the appropriate flags appear in the form header. In response to the Form data loaded trigger, another behaviour is called that uses a Client workflow to define a 'client object' that contains all the required 'header data' as field values.

The following section shows how to use the Current locale value resolver to extract the country identifier for the 'country' from the 'locale with country'.

NOTE◄ In this case, it is assumed that when defining a country-specific language, it complies with the convention (see Locale) that the internal 'name' of the dynamic enumeration value links the flag for the global locale to the two-character ISO-3166-alpha2 country flag for the referenced country via an underscore ('_'). In the system-provided path ./assets/ammap/flags/, there is a png graphic file for most country flags that represents the corresponding 'flag'.

The Set value event action shown on the right assigns the relative file path for the Image/Icon element to the country field of the 'client object', which is displayed optionally for country-specific languages. The file path is built using a Concat strings value resolver:

  • The first component of the Concat strings defines the static text for the base path for the 'flag' graphic files:
    ./assets/ammap/flags/

  • The second component of the Concat strings obtains the Current locale (possibly 'with country'). The 'Name' (name) property is extracted from the dynamic enumeration value returned by the concatenated Object property value resolver and passed on to the subsequent Replace text resolver.

  • In the Replace text value resolver, the Current locale is queried again as Search text, but this time with the option Locale without country. The 'Name' (name) property is extracted from the return value again. The underscore ('_') is added here per Concat strings. This combination is deleted from the name of the 'Locale with country'. Therefore, no value is entered under Replace with.

  • Since the filenames for 'flags' use the lowercase country identifier as the filename, the concatenation is followed by a Lower case value resolver before the uniform file extension (.png) is appended as the third component of the Concat strings.

images/download/attachments/91135153/image2022-2-10_17-9-57-version-1-modificationdate-1644509397734-api-v2.png

Runtime example:

images/download/attachments/91135153/image2022-2-10_10-23-3-version-1-modificationdate-1644484983283-api-v2.png

  • The image shows the section of a data input form for shipment details already shown at the beginning of this chapter.

  • However, the Locale 'German (Switzerland)' (de_CH) is selected in the session shown.

Further runtime example:

images/download/attachments/91135153/image2022-2-10_15-25-4-version-1-modificationdate-1644503104599-api-v2.png

  • This image shows the appearance of the same shipment details input form after the following steps have been performed:

    • An additional supported language 'Klingon' has been created in the dynamic enumeration for Locale, which is assigned the internal 'name' (name) xt_KG.

    • A small image of the Klingon flag was uploaded with the File manager (relative file path: ./assets/ammap/flags/xt_kg.png).

    • For the user, 'Klingon' was selected via Change locale and the session was logged off and on again.

  • What happens at runtime?

    • The name xt_KG for the language 'Klingon' formally refers to a global locale with the randomly chosen name xt, which is not defined in the system.

    • Therefore, the language predefined by the system 'English' (en) is effective and also specified by the Current locale value resolver per Locale without country option (see the 'Locale' flag on the left in the image).

    • The Replace text value resolver in the Client workflow therefore attempts to eliminate the prefix en_ which is not found in xt_KG.

    • Therefore, the name xt_KG is assigned to the formal country-specific language 'Klingon' without any substitution, but in lowercase letters as the file name for the 'locale' flag (right in the image), whose file name should therefore be xt_kg.png.