luci-translation

添加中英文模块

make menuconfig中选上以下两个模块:

  • luci-i18n-chinese
  • luci-i18n-english

翻译文件格式

1
2
msgid "Action"
msgstr "动作"

msgid:是指ID,不是英文译文,并不是指英文译文就一定是跟此msgid一致了。

msgstr:是指译文。

注意:中英文的话,luci/po/zh_CNluci/po/en底下对应的po文件都要改。
例如只改了中文,没添加英文,则使用此msgid时,选择英文语言会找不到英文译文,则直接显示此msgid

添加/修改翻译文件

base.po是选上了中英文模块之后,就会自动编译上去的,可以直接改。

注意:luci/po/zh_CN/base.poluci/po/en/base.po都得写上对应翻译。

luci/applications目录,按照该目录的其它文件夹,再添加一个文件夹:如example文件夹。

则需要在make menuconfig的时候选上luci-app-example模块。

再添加luci/po/zh_CN/example.poluci/po/en/example.po,写上对应翻译。

po文件最终是要编译成lmo文件的,所以可以按照格式手动添加po文件,如:luci/po/zh_CN/test.poluci/po/en/test.po

然后利用po2lmo工具直接编译成lmopo2lmo工具是编译过固件才有的,即make之后才有的,具体位置find一下吧。

1
2
po2lmo test.po test.en.lmo    # 必须添加en标识,否则不识别
po2lmo test.po test.zh-cn.lmo # 必须添加zh-cn标识,否则不识别

然后把生成的lmo文件扔到路由器的/usr/lib/lua/luci/i18n/目录下

然后需要在路由器的/usr/lib/lua/luci/controller里面的文件指定使用此lmo翻译

1
entry({"admin", "system", "system"}, cbi("admin_system/system"), _("System"), 1).i18n = "test"

使用方法

htm文件里

1
2
3
<%+header%>                                                                    
<h1><%:Action%></h1>
<%+footer%>

语言切换

/etc/config/luci
1
2
3
4
5
6
7
8
config core 'main'
option resourcebase '/luci-static/resources'
option mediaurlbase '/luci-static/openwrt.org'
option lang 'en' # 或者 zh_cn,取值是根据下面的option来的

config internal 'languages'
option zh_cn 'chinese'
option en 'English'