Metabase中文汉化问题解决

Metabase的更新速度还是比较快的,现在官方已经更新到v0.31.2( 2018-12-05),最新的版本中已经支持了中文的翻译了。先来回顾一下之前版本的一个说明:


When you have added/edited tagged strings in the code, run ./bin/i18n/update-translations to update the base locales/metabase.pot template and each existing locales/LOCALE.po

The workflow for translators in starting a new translation, or editing an existing one:

  1. You should run ./bin/i18n/update-translations first to ensure the latest strings have been extracted.
  2. If you’re starting a new translation or didn’t run update-translations then run ./bin/i18n/update-translation LOCALE
  3. Edit ./locales/LOCALE.po
  4. Run ./bin/i18n/build-translation-resources
  5. Restart or rebuild Metabase, Test, repeat 2 and 3
  6. Commit changes to ./locales/LOCALE.po and ./resources/frontend_client/app/locales/LOCALE.json

大致的意思是通过脚本先生成json 文件,并放到./resources/frontend_client/app/locales/中完成国际化翻译,最新版本在locales新增了zh.po文件:

msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: POEditor.com\n"
"Project-Id-Version: Metabase\n"
"Language: zh-CN\n"
"Plural-Forms: nplurals=1; plural=0;\n"

#: frontend/src/metabase/admin/databases/components/CreatedDatabaseModal.jsx:24
msgid "Your database has been added!"
msgstr "数据库添加成功!"
......

里面就是我们的翻译啦,若是直接使用Metabase.jar,只需要官方下载 地址,然后输入

java -Duser.country=CN -Duser.language=zh -jar metabase.jar

启动后,输入localhost:3000打开:

在这里插入图片描述

Metabase二次开发环境中汉化

此时,需要我们将zh.po文件转换成json文件,并将其放入./resources/frontend_client/app/locales/ 文件夹中,若无创建文件夹放入。

若你的开发项目版本过低,可能不会支持更多的语言,需要更改.\resources\locales.clj:

{
  :locales  #{"en" "fr" "es" "nb" "pt" "zh"}
  :packages ["metabase"]
  :bundle   "metabase.Messages"
}

增加你添加的语言,此时才能在系统中更改,否则即使加入了zh的po和json也不显示。
操作完成后,重新启动你项目:

yarn run build-hot
lein ring server

可以看到语言已经显示中文了:
在这里插入图片描述

zh.po文件转换成json文件可以根据开头的模式进行处理转换,这里我也提供一份已经转换好的json文件供大家下载:下载地址

发布了89 篇原创文章 · 获赞 28 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/iceyung/article/details/86140234
今日推荐