Search code examples
javalocalelowercase

Lowercase of nouns not correct in German


My application uses resouce bundles for different languages (I18N).

string.toLowerCase()

Lowercase is used all over the application to combine sentences.

problem: lowerCase is not correct for German nouns.

Resource bundle:

  • English: resource_day = Day
  • German: resource_day = Tag

Sentence:

  • in English: This is the first day.
  • in German: Dies ist der erste Tag.

Like you can see: The German language uses capital letters for the nouns.

Code:

sentence = resource_start + number + resource_day.toLowerCase();

What is the best way to differentiate the english and german language?


Solution

  • The best way to do that would be to store full sentences in your resources and use placeholders for the variable parts:

    EN

    resource_day = This is the {0} day.
    day_first = first
    

    DE

    resource_day = Dies ist der {0} Tag.
    day_first = erste
    

    And use it as

    String day_number = "day_first";
    MessageFormat.format(RESOURCE_BUNDLE.getString("resource_day"), 
       RESOURCE_BUNDLE.getString(day_number);