Language

Internationalization of an application user interface

Inline internationalization

You can provide the various translations directly in the code:

text "[l]Hello[fr:]Bonjour[de:]Guten tag"

You need to use an UTF8 text editor to do so.

External internationalization

Assuming that the module you are writing is /my_org/my_app/my_module.ui, you write in the code:

text "[l]Hello"

and then you provide an external /my_org/my_app/my_module.fr file with:

"Hello" "Bonjour"

and another one /my_org/my_app/my_module.de with:

"Hello" "Guten tag"

The external files must be UTF8 encoded.

Selecting the prefered language

The language assigned to each user is defined in the 'language' field of the user account.

How it works

Internationalization is mostly implemented in /pliant/language/type/text/language.pli
Each language is automatically assigned an index at the first time it is used. The default language, which is always 'en' is always assigned index 0. See code for extra details.

An internationalized string has type lStr ('l' stands for 'language'):

var lStr s
set "en" "Hello"
s set "fr" "Bonjour"
var Str t := s get "fr"

We could get the same through using indexes instead of strings to specify the language:

var lStr s
s set 0 "Hello"
var Int i := language_index "fr"
s set i "Bonjour"
var Str t := s get i

When you write:

"[l]Hello"

as opposed to

"Hello"

Pliant parser produces an lStr constant instead of an Str constant, so you can write:

var lStr s := "[l]Hello[fr:]Bonjour"

The most important method for lStr is casting to a standard string:

function 'cast Str' l -> s
  arg lStr l ; arg Str s

so that you can also write:

var Str t := s

and it is the same as::

var Str l := language
var Str t := s get l

'language' function first picks the 'language_index' field of the current thread header.
When your application is accessed through Pliant UI interface, this field is transparently set when the client logs to the server, according to the user account 'language' database field.
Then, 'language' function returns the string associated with the language index.

As a summary, in the end, when you write:

text "[l]Helio[fr:]Bonjour"

it produces the same result as:

var lStr s := "[l]Hello[fr:]Bonjour"
var Str l := language
var Str t := s get l
text t