Appway provides support for a complete multi-language framework based on language labels. Labels are used to translate text shown in the Portal into different languages supported by your solution. Instead of entering text into your Screens, enter the relevant text as Labels. You can then enter the translation of this text in different languages, without having to manually create multiple, language-specific Screens. Labels are translated to the user's language on the fly.
How does Appway know which language to display in the UI? Appway uses a multi-level strategy to determine users' language preferences. It considers all possible language configuration possibilities, starting with HTTP Query parameters and Session Attributes, through to Cookies and persistent user-based and system-based configurations.
As an example, the text in a Screen may read, "First name" and "Last name". If this text has been created using Labels, a user with the language preference set to English still sees, "First name" and "Last name". But if the language preference of the user is set to German, the same text is then displayed as "Vorname" and "Nachname", if a German translation has been provided for the Labels.
To determine what language is displayed in users' web browsers, Appway processes the following 10 steps for each web request.
| Configuration Type | Priority | Description |
| Query Parameter | 1 | The most common use of languages is the HTTP Query parameter transported in the URL as a name value pair.
http://host/.../...?language=en The lifetime of the Language Preference is limited to the request and is not persisted. |
| URL Path | 2 | Similar to the Query Parameter, the Language Preferences are transported via the URL. http://host/.../.../language/en The lifetime of the language setting is also limited to the request but can be cached. |
| Session Attributes | 3 | Language Preferences can be stored as session Attributes. This is commonly used in Web Application to remove information from the HTTP Query String. Appway provides a set of Script Functions to support Create, Read and Write operations on any Session Attributes.
HTTPSESSIONSET('language','en_US') // sets the name=value to the User's HTTP Session
String $language := HTTPSESSIONGET('language') //returns 'en_US'
HTTPSESSION(true); // get or creat the User HTTP Session Language Preference is deleted as soon as the HTTP Session becomes invalid |
| Cookie | 4 | Similar to the HTTP Session method, Cookies provide a simple persistence for Language Preferences. Here Appway also provides a set of Script Functions to Create and Read Cookies. HTTPCOOKIESET('language','en_US') // sets the name=value to the User's Cookie
String $language := HTTPCOOKIEGET('language') // returns 'en_US'
note: a lifetime can be set when creating the Cookie. Language Preference is deleted as soon as the Cookie is manually removed from the Browser or when the Cookie's Lifetime expires. |
| User Preferences | 5 | The Language Preference can be stored as a User Property for registered users in Appway. Appway provides a set of Script Functions to Get and Set User Preferences: USER().setPreference('language','en_US')
String $language := USER().getPreference('language') // returns 'en_US' User Preferences are stored as long as the User exists within Appway's User Management. |
| Browser Language | 6 | If none of the above configurations provides a valid Language Preference, the Web Browser Language Settings are considered. Appway searches for a best match on the provided language strings according to the priority provided by the Web Browser. |
| Default Language | 7 | Appway provides a configuration property which can be set to manually define the default platform language. nm.default.locale = en The Appway Model must contain the languauage set in the nm.default.locale as a Appway Business Object |
| Java Configuration | 8 | The default platform language can be set via Java Configuration Properties. Java -Duser.language=en |
| System Setting | 9 | If none of the above language decisions return valid Language, the System (OS) settings are used as default preferences. |
| Nothing Found (Fallback) | 10 | If Appway does not retrieve any Language Preference, there is no language label corresponding to any Language Label or there is a missing translation within the Language Label, Appway will display the Label ID and the preferred language. [LABEL:label.id] |