Angular 2+ 本地化 (i18n) rtl 支持 [英] Angular 2+ localization (i18n) rtl support
问题描述
在本地化的 Angular 2+ 应用程序中添加从右到左 (rtl) 支持的最佳做法是什么(例如,对于希伯来语和阿拉伯语)?我浏览了几个教程,包括 Internationalization (i18n) 但似乎没有一个涵盖这一点.例如,我希望在应用程序的构建步骤中添加 html 方向属性(例如 <html dir="rtl">
)以及在 18n 属性中定义的翻译.
What is the best practice for adding right to left (rtl) support into a localized Angular 2+ app (e.g. for Hebrew and Arabic languages)? I looked through several tutorials including Internationalization (i18n) but none seem to be covering that. I would expect, for example, the html direction property (e.g. <html dir="rtl">
) to be added along with translations defined in 18n attributes at the build step of the app.
推荐答案
可以将 i18n-dir
添加为 在文档中描述.因此,到目前为止,我发现的最佳方法是将 i18n-dir dir="ltr"
(其中 ltr
是默认方向)添加到根中的根元素组件模板(例如 app.component.html
)像这样:
It is possible to add i18n-dir
as described in the docs. So, the best approach I found so far is to add i18n-dir dir="ltr"
(where ltr
is a default direction) to the root element in the the root component template (e.g. app.component.html
) like so:
<div i18n-dir dir="ltr">
<!-- The rest of the content -->
</div>
一旦您生成翻译文件,相应的 trans-unit
将出现在每个文件中,其中 source
包含默认方向,即 ltr
在这个案例.因此,您只需将单元的 target
设置为对应语言的 rtl
即可.
Once you generate translation files a corresponding trans-unit
will appear in each of them with source
containing default direction, which is ltr
in this case. So, you just need to set the target
of the unit to rtl
for corresponding languages.
这篇关于Angular 2+ 本地化 (i18n) rtl 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!