0

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??

chavaone
  • 183
  • 3
  • 9

2 Answers2

0

If the tool jq (http://stedolan.github.io/jq/) is an option for you, below might work;

$ curl -s https://raw.githubusercontent.com/chavaone/gnomecat/master/data/languages.json | jq .languages[43].name
"English"
Kokkie
  • 546
  • 6
  • 15
  • Umm, I guess that some script using that tool could works. But I was thinking in a solution similar to the one I use with XML ui files where the string fetch it's is made automatically by gettext or intltool. Thank you anyway :) – chavaone Jul 28 '14 at 08:35
  • Probably I should have mentioned that I'm writing a desktop program :S – chavaone Jul 28 '14 at 09:53
0

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

[...]
chavaone
  • 183
  • 3
  • 9