Search code examples
jsongettextxgettext

How do I get strings from a JSON file?


I'm writing a internationalized desktop program written in Vala where a use an extern JSON file to store a list of languages.

I'm using gettext for l10n so if I get the string from the json file and I do something like _(string_var) I could get the translated string. The problem is that I don't know how can I add the string to the pot file using xgettext or some similar tool.

Any idea??


Solution

  • The solution I finally use was to modify the JSON file to use double quoted strings only when I wanted to translate that string. For example:

    {
        'code' : 'es',
        'name' : "Spanish; Castilian",
        'pluralform' : 'nplurals=2; plural=(n != 1);',
        'default-team-email': 'gnome-es-list@gnome.org'
    }
    

    In the previous piece of JSON file the only string I wanted to translate was "Spanish; Castillian". Then in the POTFILES.in, I just use the gettext/quoted type.

    # List of source files containing translatable strings.
    # Please keep this file sorted alphabetically.
    [encoding: UTF-8]
    [type: gettext/quoted]data/languages.json
    [type: gettext/quoted]data/plurals.json
    [type: gettext/glade]data/ui/appmenu.ui
    
    [...]