【问题标题】:Having trouble getting xliff tags working in my strings.xml无法让 xliff 标记在我的 strings.xml 中工作
【发布时间】:2015-10-23 15:51:54
【问题描述】:

我已阅读官方文档并查看其他人在 SO 上所做的事情,但在添加 xliff 标签后我无法让我的字符串工作。我已经导入了 xliff 命名空间

strings.xml

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="string_name">
        Your goal is maintaining your levels between 
        <xliff:g id="test1" example="130">%1$d</xliff:g>
        <xliff:g id="test2" example="mg/DL">%2$s</xliff:g>and 
        <xliff:g id="test3" example="110">%3$d</xliff:g>
        <xliff:g id="test4" example="mg/DL">%4$s</xliff:g>
</string>

代码

String raw = getString(R.string.string_name);
return String.format(raw, customGoal.getGoalValueLow(), units, customGoal.getGoalValueHigh(), units);

【问题讨论】:

    标签: android internationalization


    【解决方案1】:

    我手头没有 Android Studio 来重现您的问题,但这里猜测可能是什么问题:

    XLIFF 标准没有为&lt;g&gt; 元素列出属性example(请参阅here)。尝试删除它们是否会有所作为。 XLIFF 允许您添加自己的属性,但如果您这样做,属性值应以“x-”开头(请参阅here)。

    如果你想告诉翻译者占位符代表什么,你也可以使用ctype属性,或者选择更具描述性的ID:

    <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <string name="string_name">
            Your goal is maintaining your levels between 
            <xliff:g id="maxValue" ctype="x-number">%1$d</xliff:g>
            <xliff:g id="measurementUnit" ctype="x-unit">%2$s</xliff:g>and 
            <xliff:g id="minValue" ctype="x-number">%3$d</xliff:g>
            <xliff:g id="measurementUnit" ctype="x-unit">%2$s</xliff:g>
    </string>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-01
      • 2015-07-06
      • 1970-01-01
      • 2014-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多