【发布时间】:2018-11-23 04:19:15
【问题描述】:
我在这里阅读了整个文档:https://angular.io/guide/i18n
我不知道应该如何处理这种性质的 html 标记:
<div i18n="@@myId" class="title-text">{{currentPage}}</div>
或者这样的:
<div i18n="@@myId" class="title-text" [innerHTML]="currentPage"></div>
它根本没有提及任何可变文本,就好像他们只是假设我们将所有名称和文本硬编码到 html 中一样。
语言文件应该是这样的:
<?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="myId" datatype="html">
<source>Hello</source>
<target>Bonjour</target>
</trans-unit>
</body>
</file>
</xliff>
我是否应该做这样的事情来处理 var 的多种可能性?
<?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="myId" datatype="html">
<source>Title 1</source>
<target>Titre 1</target>
<source>Help 2</source>
<target>Aide 2</target>
<source>New 3</source>
<target>Nouveau 3</target>
</trans-unit>
</body>
</file>
</xliff>
我认为这行不通。如何处理变量?
更新:
如果我使用他们的语言文件生成工具:
ng xi18n --output-path locale --out-file english.xlf --i18n-locale fr
我明白了:
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="fr" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="9f3e56faa6da73b83f4646a1e074b970891894da" datatype="html">
<source><x id="INTERPOLATION" equiv-text="{{currentPage}}"/></source>
<context-group purpose="location">
<context context-type="sourcefile">app/logged.in/top.bar/top.bar.component.ts</context>
<context context-type="linenumber">85</context>
</context-group>
<note priority="1" from="description">the title of the current route</note>
</trans-unit>
</body>
</file>
</xliff>
很确定equiv-text="{{currentPage}}" 是垃圾。但它可能还需要测试。
与此同时,我无法让 ng serve 接受新配置。
再次更新:
让ng serve --configuration=fr工作
您必须进一步编辑angular.json,官方文档中没有指定,但他们确实在这里讨论过:https://github.com/angular/angular-cli/wiki/stories-internationalization
好吧,我添加了一个 <target>Title</target> 并且它可以工作,但这当然意味着现在 var 的每个值都返回“title”,无论如何。
在到处放置i18n 标签后,我在代码中遇到了这个问题:
<dropzone [message]="valid? '' : 'Placez ici votre fichier Excel csv à Ajouter aux lignes ci-dessous. (Ces lignes apparaîtront à la fin de la table)'" (success)="uploaded()"></dropzone>
那么现在呢?如何翻译传递给 dropzone 的消息?
【问题讨论】:
-
为什么没有实际文本的元素需要翻译?
标签: angular angular-i18n