我正在尝试找到一种方法来获取 Angular 6 项目文件(ts 和样式以及 html 文件)中的所有文本字符串,以便使用文件路径自动生成嵌套的 JSON 对象。例如。在组件 html 文件中:
app/shared/forms/categories/categories.component.html:
<a id="input-categories">This string</a>
<a class="btn accept">This button</a>
提取后,在 en.json 中:
{
"shared": {
"forms": {
"categories":{
"a-input-categories": "This string",
"a-btn-accept": "This button"
}
}
}
}
我看过ngx-translate-extract ,但它只会提取已经可翻译的 {{ name.space.here |翻译 }}
管道等
如果这是不可能的,是否有一种方法可以使用某种默认标记(例如 trans
)以这种方式“标记”每个字符串:
<a id="input-categories" trans>This string</a>
<a class="btn accept" trans>This button</a>
我的问题是前端开发人员已经对所有内容进行了硬编码,现在我们正在查看需要从标记和代码中提取的 4 位字符串以进行翻译。
最佳答案
你可以使用 ngx-translate-extractor
https://github.com/biesbjerg/ngx-translate-extract
ngx-translate-extract --input ./src --output ./src/assets/i18n/template.json
关于javascript - 如何从 Angular 6 中的组件中提取文本进行翻译 (ngx-translate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51481382/