多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 6. 模板界面多语言 ## 模板界面多语言 静态文件目录下创建lang文件夹,如下创建了简体、繁体,默认英文对应。 ![](https://img.kancloud.cn/45/81/45814d15aab96a8ac64854dfa9f455bc_268x267.png) zh-cn.json,模板全局可使用,写在zh-cn文件夹下的index.json,只在index控制器下有效。 ## 格式 zh-cn文件 ``` <pre class="calibre16">``` <span class="token5">// 简体</span> <span class="token1">{</span> <span class="token4">"The title is right at the top of the pag"</span><span class="token1">:</span> <span class="token4">"标题就在页面的顶端"</span> <span class="token1">}</span> ``` ``` zh-tw文件 ``` <pre class="calibre16">``` <span class="token5">// 繁体</span> <span class="token1">{</span> <span class="token4">"The title is right at the top of the pag"</span><span class="token1">:</span> <span class="token4">"標題就在頁面的頂端"</span> <span class="token1">}</span> ``` ``` 在模板html写上: ``` <pre class="calibre16">``` <span class="token1">{</span><span class="token1">:</span><span class="token6">lang</span><span class="token1">(</span><span class="token4">'The title is right at the top of the pag'</span><span class="token1">)</span><span class="token1">}</span> <span class="token5">// 系统会根据当前语言,输出对应的语言包。如果没找到,就是默认英文。</span> ``` ``` ## 语言切换方法 将下面的代码复制到合适的位置,点击链接即可完成切换。 ``` <pre class="calibre20">``` <span class="token"><</span>li class<span class="token">=</span><span class="token4">"nav-item"</span><span class="token">></span> <span class="token"><</span>a href<span class="token">=</span><span class="token4">"?lang=zh-cn"</span><span class="token">></span>中文<span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token"><</span>a href<span class="token">=</span><span class="token4">"?lang=zh-tw"</span><span class="token">></span>繁体<span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token"><</span>a href<span class="token">=</span><span class="token4">"?lang=en"</span><span class="token">></span>英文<span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token"><</span><span class="token">/</span>li<span class="token">></span> ``` ```