Skip to content

Commit

Permalink
Add support for multiple languages
Browse files Browse the repository at this point in the history
gettext supports supplying multiple languages using the colon character
$ LANGUAGE=pt_BR:pt_PT:en_US foo bar
which are used as fallback: when a translation for the first one is not
available, the second language is used. If no language contains
a translation for the string `msgid` is returned.

This patch adds this support into gotext.

1/ config struct
 - 'language' was renamed to 'languages' and is a slice of strings
 - 'storage' was renamed to 'locales' and is a slice of Locale pointers

2/ loadStorage()
 - all loaded languages are iterated over

3/ GetLanguages()
 - new function returns the languages from the config
 - GetLanguage() uses the first element of it, keeping the compatibility

4/ SetLanguage(), Configure()
 - the language string is split at colon and iterated over

5/ Get*()
 - languages are iterated and the first translation for given string is
   returned

6/ IsTranslated*()
 - new optional parameter (langs) has been added

7/ Locale.GetActualLanguage()
 - it checks the filesystem and determines what the actual language code
   is: for 'cs_CZ', just 'cs' may be returned, depending on the actual
   name of the .mo/.po file.

8/ GetLocales/GetStorage, SetLocales/SetStorage
 - Following recent changes, created public functions to manipulate with
   global configuration's locales. The *Storage functions are renamed
   in later commit to reduce the amount of changes in one commit.
  • Loading branch information
m-horky committed Dec 19, 2023
1 parent 12a9914 commit 4ec5f39
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 86 deletions.
Loading

0 comments on commit 4ec5f39

Please sign in to comment.