Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple languages #85

Merged
merged 3 commits into from
Apr 9, 2024

Commits on Dec 19, 2023

  1. Add support for multiple languages

    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.
    m-horky committed Dec 19, 2023
    Configuration menu
    Copy the full SHA
    4ec5f39 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f7ff9bf View commit details
    Browse the repository at this point in the history

Commits on Jan 9, 2024

  1. Rename 'storage' to 'locale'

    As the package matured, it makes sense to use unified names everywhere.
    Since the config holds Locale objects, the variable is called 'locales'.
    
    This patch finishes the work and updates the 'loadStorage' function
    to be called 'localLocales' with argument 'rebuildCache' instead of
    'force'.
    m-horky committed Jan 9, 2024
    Configuration menu
    Copy the full SHA
    8979030 View commit details
    Browse the repository at this point in the history