Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localizing a string containing list of names

I have string containing a list of name like below: "John asked Kim, Kelly, Lee and Bob about the new year plans". The number of names in the list can very. How can I localize this in Java? I am thinking about ResourceBundle and MessageFormat. How will I write the pattern for this in MessageFormat? Is there any better approach?

like image 725
Rejeev Divakaran Avatar asked Dec 09 '11 15:12

Rejeev Divakaran


2 Answers

Localizing an (inline) list is more than just translating the word “and.” CLDR deals with the issue of formatting lists, check out their page on lists. I’m afraid ICU doesn’t have support to this yet, so you might need to code it separately.

Another issue is that you cannot expect to be able to use names as such in sentences like this. Many languages require the object to be in an inclined form, for example. In Finnish, your sample sentence would read as “John kysyi Kimiltä, Kellyltä, Leeltä ja Bobilta uudenvuoden suunnitelmista.” So you may need to find out and include different inclined forms of the names. Moreover, if the language used does not have Latin alphabet, you may need transliterated forms of the names (e.g., in Arabic, John is جون). There are other problems as well. In Russian, the verb corresponding to “asked” depends on the gender of the subject (e.g., спросила vs. спросил).

I know this sounds complex, but localization is often complex. If you target a limited set of languages only, things can be much easier, so it is important to defined your goals—perhaps accepting some simplifications that may result in grammatically incorrect expressions. But for localization that is to cover a wide range languages, you may need to make the generating function localized. That is, you would have, for each language, a function that accepts a list of names as arguments and returns a string representing the statement, possibly using resource files containing information (transliterated form, different inclined form, gender) about proper names that may appear.

In some situations, you might even consider generating the sentence in English, then sending it to an online translator. For example, Google Translator can deal with some of the issues that I mentioned. It surely produces wrong translations a lot, but for sentences with grammatically very simple structure, it might be a pragmatic solution, if you can accept some amount of errors. If you consider trying this, make sure you test sufficiently how the automatic translator can handle the specific sentences you will use. Quite often you can improve the results by reformulating the sentences. Dividing a sentence with several clauses into separate sentences often helps. But even your simple sentence causes problems in automatic translation.

You might avoid some complications if you can reformulate the sentence structure, e.g. so that all the nouns appear in the subject position and you avoid “packed” expressions like “new year plans.” For example, “John asked what plans Kim, Kelly, Lee, and Bob have for the new year” would be simpler, both for automatic translation and for pattern-based localization.

like image 75
Jukka K. Korpela Avatar answered Nov 18 '22 21:11

Jukka K. Korpela


You could do something like:

"{0} asked {1} about the new year plans"

where 0 is the first name and 1 is a comma-separated list of the other names.

Hope this helps.

like image 27
cjstehno Avatar answered Nov 18 '22 21:11

cjstehno