如何使用 gettext 处理未定义长度的列表?

发布于 2024-12-07 20:25:12 字数 271 浏览 0 评论 0原文

我想翻译以下格式的字符串:

删除文件 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

壹場煙雨 2024-12-14 20:25:12

这个就比较复杂了。

实际上,您似乎只需要在单数和复数形式之间进行选择(尽管语言可以有多个复数形式)。
所以基本上您想删除这个文件:%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),但理论上你可以使用这些信息来创建一个列表。
在另一个答案中,我声称实际上不可能在一般情况下创建此类列表(无论使用哪种语言),并且人们倾向于使用列表视图控件进行选择或将数据呈现为垂直列表以避免出现问题。您的示例需要修改为:

These file(s) would be deleted:  
toto  
tata  
titi  
Are you sure?

这可能会有问题(它可能不适合屏幕),但这是人们经常做的事情,以避免外语列表出现问题。

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? or Do 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) or Do you want to translate these %n files: %s translated either as Czy chcesz usunąć te %n pliki: %s? or Czy 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:

enter image description here

{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 to toto, 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:

These file(s) would be deleted:  
toto  
tata  
titi  
Are you sure?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文