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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With