luci-translation
添加中英文模块
make menuconfig
中选上以下两个模块:
- luci-i18n-chinese
- luci-i18n-english
翻译文件格式
1 | msgid "Action" |
msgid
:是指ID
,不是英文译文,并不是指英文译文就一定是跟此msgid
一致了。
msgstr
:是指译文。
注意:中英文的话,luci/po/zh_CN
和luci/po/en
底下对应的po
文件都要改。
例如只改了中文,没添加英文,则使用此msgid
时,选择英文语言会找不到英文译文,则直接显示此msgid
。
添加/修改翻译文件
base.po
是选上了中英文模块之后,就会自动编译上去的,可以直接改。
注意:luci/po/zh_CN/base.po
和luci/po/en/base.po
都得写上对应翻译。
在luci/applications
目录,按照该目录的其它文件夹,再添加一个文件夹:如example
文件夹。
则需要在make menuconfig
的时候选上luci-app-example
模块。
再添加luci/po/zh_CN/example.po
和luci/po/en/example.po
,写上对应翻译。
po
文件最终是要编译成lmo
文件的,所以可以按照格式手动添加po
文件,如:luci/po/zh_CN/test.po
和luci/po/en/test.po
。
然后利用po2lmo
工具直接编译成lmo
,po2lmo
工具是编译过固件才有的,即make
之后才有的,具体位置find
一下吧。
1 | po2lmo test.po test.en.lmo # 必须添加en标识,否则不识别 |
然后把生成的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 | <%+header%> |
语言切换
1 | config core 'main' |