Output all language strings in Revel?

huangapple go评论100阅读模式
英文:

Output all language strings in Revel?

问题

我正在使用Go开发一个API服务器,目前服务器负责处理所有客户端的翻译。当API客户端获取特定数据时,它还会请求给定部分可用的翻译。

理想情况下,我希望有以下文件夹结构:

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

其中newshome是不同的模块。

现在我对Revel有一个问题,是否可以获取给定模块和给定区域设置的所有语言字符串?例如,获取en-US的所有home字符串。

编辑:

我希望输出(可以返回给客户端)是一个键值对形式的翻译字符串。

希望能得到一些指导。

英文:

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.

答案1

得分: 3

我觉得Revel使用基于消息的翻译(就像gettext一样),所以你需要原始字符串来获取翻译。这些字符串存储在Config对象中,Config对象本身存储在i18n.gomessages中,按语言排序。

正如你所见,这个映射是不可导出的,所以你无法访问它。修复这个问题的最好方法是编写一个函数(通过提供语言来获取配置)或者导出一个现有的函数并为Revel创建一个拉取请求。

你可以通过复制loadMessageFile的代码或者分叉你自己的Revel版本并导出loadMessageFileparseMessagesFile来解决这个问题。这也是一个很好的机会来创建一个拉取请求。

请注意,本地化存储在由robfig/config解析的INI文件格式中,因此手动解析也是一种选择(尽管不推荐)。

英文:

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).

huangapple
  • 本文由 发表于 2013年9月4日 02:13:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/18598877.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定