12

This is about best practices in general, not specific for a single language, database or whatever

We all have to deal with generated output where you can be reporting "one products" or "two product". Doesn't read very well... Some just solve this by using "one product(s)" or "number of products: (1)" and others might have other solutions.

Things could be even more complex in different spoken languages! In French, when you have zero products, you would use the singular form, not the plural form! (Zero product) Other languages (Chinese, Japanese) might even lack these grammatical differences or have more than two different words to indicate something about the number of products. (A plural and a greater plural, for example.)

But to keep this simple, let's focus on the languages that have both singular and plural words.

When setting up a new project, which also has to generate reports, how do you deal with singular and plural words? Do you add two name fields in your database for singular and plural form? Do you add additional rules in the code to transform words from singular to plural? Do you use other tricks?

When working on a project that needs to track singular and plural forms, how do you deal with this?

4

7 に答える 7

10

gettext一般的に、そしてngettext特に見てみることをお勧めします。アプリケーションを翻訳しない場合でも可能です。ドキュメントのこの部分に進んでください。多かれ少なかれすべての言語の実装があり、選択した言語にこのサポートがなくても、アイデアを借りることを止めるものは何もありません.

于 2009-09-17T11:02:37.900 に答える
2

Perl では、これはLingua::EN::Inflectによって包括的に解決されます。大規模なディクショナリを使用し、ルールに対するすべての例外を慎重に処理します。また、'a' や 'an' なども実行し、比較も処理します。

悲惨な詳細については、論文を参照してください。

于 2009-09-17T11:37:26.113 に答える
1

更新されただけで、CLDRには言語に関する複数のルールがあり、ICUには実装があります。

于 2011-11-11T17:36:57.793 に答える
1

これを読んで実装してください。完了したら (数年後) 報告してください。個人的には、(s) アプローチに満足しています ;) (これがすべての言語で機能するわけではないことは言うまでもありません)。

于 2009-09-17T11:10:57.040 に答える
1

通常、表示したい値を人間が読めるテキストに再フォーマットする、ある種のフォーマッタを介してテキストを送信します。これにより、「製品」テキストも変更される可能性があります。Java には、このような変更をサポートする MessageFormat クラスがあります。[1] の例を参照してください。

[1] http://java.sun.com/j2se/1.5.0/docs/api/java/text/MessageFormat.html

于 2009-09-17T11:01:40.913 に答える
0
Number of products:  1 
Number of products:  4
Number of products:  FILE_NOT_FOUND

定量的なデータを報告するために自然言語を使用しようとするのは、あまりにも面倒です。

于 2009-09-17T10:58:01.217 に答える
-4

英語のアプリケーションでは、通常、単数形を格納し、if ステートメントのグループを使用して複数形を作成するのが最も簡単で効率的です。

if( count > 1 ){
   suffix = 's';
}
于 2009-09-17T11:00:43.460 に答える