国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

詳解使用angular-cli發(fā)布i18n多國(guó)語言Angular應(yīng)用

2019-11-19 16:32:27
字體:
供稿:網(wǎng)友

在模板html標(biāo)簽中增加i18n

<h1 i18n>Hello world!</h1>

使用ng命令產(chǎn)生xlf格式的message.xlf文件

$ ng xi18n --output-path src/i18n

命令執(zhí)行后,生成 src/i18n/messages.xlf 文件

<?xml version="1.0" encoding="UTF-8" ?><xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> <file source-language="en" datatype="plaintext" original="ng2.template">  <body>   <trans-unit id="5816217f424111ae4c91dd72ee1db0ae252763b5" datatype="html">    <source>Hello World!</source>    <target/>   </trans-unit>  </body> </file></xliff>

復(fù)制message.xlf,message.en.xlf(英文版本) message.zh.xlf中文版本

<?xml version="1.0" encoding="UTF-8" ?><xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> <file source-language="en" datatype="plaintext" original="ng2.template">  <body>   <trans-unit id="5816217f424111ae4c91dd72ee1db0ae252763b5" datatype="html">    <source>Hello World!</source>    <target>Hello World!</target>   </trans-unit>  </body> </file></xliff>

<?xml version="1.0" encoding="UTF-8" ?><xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> <file source-language="en" datatype="plaintext" original="ng2.template">  <body>   <trans-unit id="5816217f424111ae4c91dd72ee1db0ae252763b5" datatype="html">    <source>Hello World!</source>    <target>哈嘍,世界!</target>   </trans-unit>  </body> </file></xliff>
$ ng serve --aot /      --i18n-file=src/i18n/messages.zh.xlf /      --locale=zh /      --i18n-format=xlf

現(xiàn)在瀏覽,顯示的是中文版本

$ for lang in en zh; do /  ng build --output-path=dist/$lang /       --aot /       -prod /       --bh /$lang/ /       --i18n-file=src/i18n/messages.$lang.xlf /       --i18n-format=xlf /       --locale=$lang; / done

這個(gè)命令執(zhí)行完畢后,生成了en和zh兩種語言版本。http://localhost:4200/en訪問英文版本,http://localhost:4200/zh訪問中文版本。--bh指定默認(rèn)版本,http://localhost:4200訪問時(shí),跳轉(zhuǎn)到默認(rèn)版本。

修改package.json文件,加入腳本

{ [...] "scripts": {  [...]  "build-i18n": "for lang in en zh; do ng build --output-path=dist/$lang --aot -prod --bh /$lang/ --i18n-file=src/i18n/messages.$lang.xlf --i18n-format=xlf --locale=$lang; done" } [...]}

這樣就可以執(zhí)行npm run build-i18n 命令,一次build多個(gè)語言版本了。

windows用戶命令

> ng build --output-path=dist/zh --aot -prod --bh /zh/ --i18n-file=src/i18n/messages.zh.xlf --i18n-format=xlf --locale=zh> ng build --output-path=dist/en --aot -prod --bh /en/ --i18n-file=src/i18n/messages.en.xlf --i18n-format=xlf --locale=en

package.json腳本

"scripts": {  "build-i18n:es": "ng build --output-path=dist/zh --aot -prod --bh /zh/ --i18n-file=src/i18n/messages.zh.xlf --i18n-format=xlf --locale=zh",  "build-i18n:en": "ng build --output-path=dist/en --aot -prod --bh /en/ --i18n-file=src/i18n/messages.en.xlf --i18n-format=xlf --locale=en",  "build-i18n": "npm run build-i18n:en ; npm run build-i18n:zh" }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 元谋县| 昌吉市| 舟山市| 横山县| 开阳县| 肇州县| 乌拉特前旗| 英吉沙县| 二手房| 衡南县| 巫溪县| 醴陵市| 南川市| 阿合奇县| 托克托县| 东丽区| 陈巴尔虎旗| 麻阳| 永新县| 越西县| 夏河县| 枣强县| 东平县| 墨玉县| 青田县| 江孜县| 自治县| 喀喇沁旗| 沧州市| 盐亭县| 图片| 隆昌县| 兖州市| 金平| 元阳县| 丰城市| 剑河县| 合阳县| 白城市| 大竹县| 临海市|