Angular 2+本地化(i18n)RTL支持 [英] Angular 2+ localization (i18n) rtl support
问题描述
在本地化的Angular 2+应用程序中添加从右到左(rtl)支持的最佳做法是什么(例如希伯来语和阿拉伯语)?我浏览了一些教程,包括国际化(i18n),但似乎没有一个涵盖这方面.我希望例如在应用程序的构建步骤中将html direction属性(例如<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屋!