6.22.11 Internationalization and Localization

Programs for end users require to address those in their native language. There is a decades old proposal for such a facility that has been split from other proposals for international character sets like Xchars (see Xchars and Unicode) and Substitute (see Substitute). Messages displayed on the screen need to be translated from the native language of the developers to the local languages of the user.

Strings subject to translation are declared with L" string". This returns a locale string identifier (LSID). LSIDs are opaque types, taking a cell on the stack. LSIDs can be translated into a locale; locales are languages and country-specific variants of that language.

L" ( "lsid<">" – lsid  ) gforth-experimental “l-quote”

Parse a string and define a new lsid, if the string is uniquely new. Identical strings result in identical lsids, which allows to refer to the same lsid from multiple locations using the same string.

LU" ( "lsid<">" – lsid  ) gforth-experimental “l-unique-quote”

Parse a string and always define a new lsid, even if the string is not unique.

native@ ( lsid – addr u  ) gforth-experimental “native-fetch”

fetch native string from an lsid

locale@ ( lsid – addr u  ) gforth-experimental “locale-fetch”

fetch the localized string in the current language and country

locale! ( addr u lsid –  ) gforth-experimental “locale-store”

Store localized string addr u for the current locale and country in lsid.

Language ( "name" –  ) gforth-experimental “Language”

define a locale. Executing that locale makes it the current locale.

Country ( <lang> "name" –  ) gforth-experimental “Country”

define a variant (typical: country) for the current locale. Executing that locale makes it the current locale. You can create variants of variants (a country may have variants within, e.g. think of how many words for rolls/buns there are in many languages).

locale-file ( fid –  ) gforth-experimental “locale-file”

read lines from fid into the current locale.

included-locale ( addr u –  ) gforth-experimental “included-locale”

read lines from the file addr u into the current locale.

include-locale ( "name" –  ) gforth-experimental “include-locale”

read lines from the file "name" into the current locale.

locale-csv ( "name" –  ) gforth-experimental “locale-csv”

import comma-separated value table into locales. first line contains locale names, “program” and “default” are special entries; generic languages must preceed translations for specific countries. Entries under “program” (must be leftmost) are used to search for the lsid; if empty, the line number-1 is the lsid index.

.locale-csv ( ) gforth-experimental “dot-locale-csv”

write the locale database in CSV format to the terminal output.

locale-csv-out ( "name" –  ) gforth-experimental “locale-csv”

Create file "name" and write the locale database out to the file "name" in CSV format.