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 #73

Merged
merged 3 commits into from Aug 29, 2023

Commits on May 15, 2023

  1. Add support for multiple languages

    gettext supports supplying multiple languages using the colon character
    $ LC_ALL=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.
    m-horky committed May 15, 2023
    Configuration menu
    Copy the full SHA
    7125c7d View commit details
    Browse the repository at this point in the history
  2. Handle special locale 'C'

    Specifying C disables all further localization.
    m-horky committed May 15, 2023
    Configuration menu
    Copy the full SHA
    831b071 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    9a5081d View commit details
    Browse the repository at this point in the history