简体   繁体   中英

How to localize country names in phrases?

I want to localize phrases like "Places in {country name}" where the country name is dynamically obtained (eg by -[NSLocale localizedStringForCountryCode:] ).

The problem is that for some country names, an article must be prepended:

  • Places in the United States ( en )

Sometimes in plural form, male or female, capitalized or not:

  • Lugares en los estados unidos ( es )
  • Lugares en las Maldivas ( es )

The article might even have to be declined according to the casus (nominative, dative etc) of the country name in the phrase:

  • Orte in der Schweiz ( de )
  • Wir fahren in die Schweiz ( de for "we go to Switzerland")

Or we even might might a different preposition:

  • Orte auf den Malediven ( de , using "auf" instead of "in" because the Maldives are islands)

Is there either a library or a good set of rules (eg regular expression based) that one could use to accomplish this?

While I'm primarily searching for an iOS solution, I'm open to port any solution from other platforms.

This problem is best solved by avoiding it altogether: localise the entire phrases, and key them by the ISO country code. The reason is that the rules are complex, not necessarily regular, and differ from language to language. Take Russian for example, where the country name itself (as opposed to just a preposition) has to be modified based on the casus in which the word appears in the sentence — I assume the same holds for various other Slavic languages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM