如何使用 gettext 处理未定义长度的列表?
我想翻译以下格式的字符串:
删除文件 toto、tata 和 titi。
第一个想法是使用 Delete files %s
但后来我想到了复数形式。
如果某些语言不在末尾添加“and”,而是使用两个不同的单词来表示最后一项和之前的一项,该怎么办?
所以这里有两个问题:
- 你知道这样的语言吗?
- 您知道处理此案的更好方法吗?
I'd like to translate strings of the following format:
Delete files toto, tata and titi.
First idea was to use Delete files %s
but then I thought about plural forms.
What if some language doesn't put 'and' at the end but, for example, two different words for the last item and the one before it.
So here are two questions:
- Do you know a language like that?
- Do you know a better way to handle this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个就比较复杂了。
实际上,您似乎只需要在单数和复数形式之间进行选择(尽管语言可以有多个复数形式)。
所以基本上
您想删除这个文件:%s吗?
或您想删除这些文件:%s吗?
。我不能说适用于所有语言,但用波兰语就可以了。然而,如果你想输入数量(这是一个相当好的主意),你最终会得到多个复数形式:
您要删除此文件吗:%s
(翻译后Czy chcesz usunąć 10 plik:{0}?
)或您要翻译这些 %n文件:%s
翻译为Czy chcesz usunąć te %n pliki: %s?
或Czy chcesz usunąć tych %n pików:%s?
。至于列表,CLDR 图表可能是一个不错的选择有关如何处理它们的信息来源 - 查找listPattern。下面我展示了波兰图表的一个片段:
{0} 和 {1} 是占位符,列表您提供的内容类似于:
toto;塔塔我蒂蒂
。我仍然不完全确定这就是它应该是什么样的(在波兰语中我更倾向于toto, tata i titi
),但理论上你可以使用这些信息来创建一个列表。在另一个答案中,我声称实际上不可能在一般情况下创建此类列表(无论使用哪种语言),并且人们倾向于使用列表视图控件进行选择或将数据呈现为垂直列表以避免出现问题。您的示例需要修改为:
这可能会有问题(它可能不适合屏幕),但这是人们经常做的事情,以避免外语列表出现问题。
This is more complicated.
Actually it seems that you need only to choose between singular and plural form (although languages could have multiple plural forms).
So basically
Do you want to delete this file: %s?
orDo you want to delete these files: %s?
. I cannot say for all languages but this would be OK in Polish.However, if you want to put quantity (which is rather good idea), you would end up with multiple plural forms:
Do you want to delete this file: %s
(Czy chcesz usunąć ten plik: {0}?
when translated) orDo you want to translate these %n files: %s
translated either asCzy chcesz usunąć te %n pliki: %s?
orCzy chcesz usunąć tych %n plików: %s?
.As for lists, CLDR charts might be a good source of information on how to handle them - look for listPattern. Below I am presenting a fragment from Polish charts:
{0} and {1} are placeholders, the list you provided would look like:
toto; tata i titi
. I am still not totally sure this is what it should like (in Polish I am more inclined tototo, tata i titi
) but in theory you could use this information to create a list.In another answer I claimed that it is actually impossible to create such lists in general case (regardless of the language) and people tend to use list view controls for selection or present data as vertical list to avoid problems. Your example would need to be modified to:
This might be problematic (it might not fit in the screen) but this is what people often do to avoid issues with lists in foreign languages.