Jon*_*tan 5 xml localization internationalization
我即将决定如何处理基于XML的UI描述格式的国际化.
格式通常如下所示:
...
<devif>
<screen id="scr1" title="Settings for this and that">
<header text="Climate readings"/>
<rd setp="123" text="Air temperature" unit="°C"/>
<rd setp="234" text="Humidity" unit="%RH"/>
<rd setp="345" text="CO2" unit="ppm"/>
<header text="Settings"/>
<wr setp="567" text="Air temperature demand" unit="°C"/>
</screen>
...
</devif>
Run Code Online (Sandbox Code Playgroud)
每个文件都包含大量屏幕,最多可包含10,000行,我们的应用程序中有十几个这样的文件.
我仍然可以改变格式以最好地满足我们的需求.那么你将如何翻译呢?
我一直在考虑一些可能的方法来解决这个问题:
第一种解决方案存在的问题是,根据上下文,英文文本可能会被翻译成不同的消息.
第二种解决方案使源文件的可读性降低(尽管不是很多),并且它不能轻松处理属性的转换.
一旦将文件翻译成5-6种语言,第三种解决方案就会使文件变得非常庞大和繁琐.
我将创建一个模板文件,例如名为“somename.xml.template”
\n\n<devif>\n <screen id="scr1" title="[SettingsForThisCard]">\n <header text="[ClimateReadings]"/>\n <rd setp="123" text="[AirTemperature]" unit="\xc2\xb0C"/>\n...\nRun Code Online (Sandbox Code Playgroud)\n\n然后,您可以为每种语言创建一堆类似 ini 的文件,其中包含:
\n\nSettingsForThisCard=您给定语言的消息
\n\n然后,您可以用从 ini 文件读取的消息替换标签。好处是如果有没有翻译的标签,很容易被检测到,不浪费翻译的精力。此外,它非常简单,因此可能不是最适合您的特定要求的方法。
\n| 归档时间: |
|
| 查看次数: |
1289 次 |
| 最近记录: |