如何使用Android xliff:g [英] How to use Android xliff:g

查看:108
本文介绍了如何使用Android xliff:g的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释xliff:g的字符串/本地化吗.

Can someone please explain the xliff:g for strings/localization.

我了解到xliff:g不应在<>内进行任何翻译,但是我很困惑如何在代码中使用它.

I understand that xliff:g is not supposed to translate anything inside the <> things, but I'm confused how exactly I'd use this in code.

我所举的一个例子是我拥有的实践西班牙语翻译:

An example I have in my case is the practice spanish translations that I have has:

<string name="order_quantity">Cantidad: <xliff:g id="quantity" example="2">%d/xliff:g</string>

我现在正在尝试使用xliff:g获取本地化字符串. id在这里是什么,它有什么作用?它叫什么?

I am now trying to get localized strings with xliff:g to work. What is id here and what does it do? And what does it call?

%d又是什么,它有什么作用? example的意义是什么?另外,如果有的话,我该怎么称呼它为代码?

Also what is the %d and what does it do? What is the point of example? Also, how would I call that into code, if at all?

为什么有人不能执行以下代码来插入以下xml:

Why can't someone just do the following code to insert the following xml:

<string name="quant">Quantity: </string>

像这样进入Java:

getString(R.string.quant) + quantity

以这种方式将数量变量简化为getString?

so that way it concactenates the quantity variable into the getString?

推荐答案

在您的示例中有轻微的错字,应该有一个结束标记:

Minor typo in your example, there should be a closing tag:

<string name="order_quantity">Cantidad: <xliff:g id="quantity" example="2">%d</xliff:g></string>

id属性仅用于标识替换参数表示的内容(在您的情况下,它表示数量).就像您说的那样,是笔记,实际上并未以编程方式使用.

The id attribute is just used to identify what the substitution parameter represents (in your case, it represents the quantity). It's as you said, a note, and not actually used programmatically.

也就是说,在Android Studio中,如果您为字符串启用了代码折叠功能,则当它显示折叠的字符串时,它将替换ID.您会看到类似这样的内容:

That said, in Android Studio, if you have Code Folding enabled for strings, it will substitute in the ID when it shows the collapsed string. You'd see something like this:

// This...
mTextView.setText(getString(R.string.order_quantity, 2));

// Will show as this when folded:
mTextView.setText("Cantidad: {quantity}");

关于第二个问题,为什么不只使用字符串连接呢?在其他语言中,替换可能不会出现在字符串的末尾.您可能会有类似的内容:

As for your second question, why not just use string concatenation? In other languages, the substitution may not go at the end of the string. You could have something like:

values/strings.xml
    <string name="order_quantity">%d items</string>

values-es/strings.xml
    <string name="order_quantity">Cantidad: %d</string>

因此,您可以看到在这种情况下,仅将字符串附加在一起不会带来有效的结果.

So you can see that in this case, simply appending the strings together would not give you a valid result.

这篇关于如何使用Android xliff:g的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆