Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output all language strings in Revel?

Tags:

go

revel

I'm developing an API Server in Go and the server (at the moment) handles all translations for clients. When an API client fetches particular data it also asks for the translations that are available for the given section.

Ideally I want to have the following folder structure:

/messages
  /home.en
  /home.fr
  /home.sv
  /news.en
  /news.fr
  /news.sv

Where news and home are distinct modules.

Now the question I have for Revel is is it possible to fetch ALL language strings for a given module and given locale? For example pull all home strings for en-US.

EDIT:

I would like the output (something I can return to the client) a key:value string of translations.

Any guidance would be appreciated.

like image 843
Peter Avatar asked Oct 21 '22 01:10

Peter


1 Answers

It seems to me that revel uses messaged based translation (just like gettext does), so you need the original string to get the translation. These strings are stored in Config objects, which are themselves stored in messages of i18n.go, sorted by language.

As you can see, this mapping is not exported, so you can't access it. The best way to fix this is to write a function for what you want (getting the config by supplying a language) or exporting one of the existing functions and create a pull request for revel.

You may workaround this by copying the code of loadMessageFile or by forking your version of revel and exporting loadMessageFile or parseMessagesFile. This also is a great opportunity to create a pull request.

Note that the localizations are stored in a INI file format parsed by robfig/config, so manually parsing is also an option (although not recommended).

like image 98
nemo Avatar answered Oct 24 '22 03:10

nemo