message-format-wg icon indicating copy to clipboard operation
message-format-wg copied to clipboard

Add message format modifier to capitalize text

Open trtrmitya opened this issue 4 years ago • 1 comments

Is your feature request related to a problem? Please describe. I am using icu4j to format messages.

I have a pattern with a variable, say "My favourite fruit is {name}.". (random example).

Now imagine that translator translates this message to another language, in which the fruit name becomes the first word of the sentence: "{name} ... blah blah.". Translator should indicate in this format string that {name} must be capitalized.

I don't want to make capitalization in my Java code, I want to leave it to format strings because it is (natural) language-dependent.

Describe the solution you'd like I would like to have some way to indicate in pattern that word should be capitalized.

trtrmitya avatar Nov 19 '21 19:11 trtrmitya

Actually, the translator shouldn't indicate this. It should be a formatting directive. Automatic (language-specific) handling should be part of the text transformation function in the formatter. ICU has some support for this for some of the built-in strings, via DisplayContext but the implementation doesn't reach MF.

If you're thinking of languages such as German that capitalize their nouns, presumably any fruit names would already be appropriately capitalized. Supplying external styling (especially involving case mapping) can produce errors and generally any "programming" (pattern logic) that the translator has to change to get the right result is a recipe for errors/gaps/problems (it's why we prefer skeletons to picture strings).

However, there are plenty of cases where one wants a specific text effect applied to the formatted value. For example, when I think of this I think of CSS text-transform and thus I might want:

My favorite fruit is APPLE ( {fruitName, text-transform: uppercase } ) My favorite fruit is Apple ( {fruitName, text-transform: capitalize }) My favorite fruit is apple / Meine Lieblingsfrucht ist Apfel ( {fruitName, text-transform: auto, pos: noun } )

aphillips avatar Mar 10 '22 20:03 aphillips

Duplicates #38 ?

aphillips avatar Jul 19 '23 17:07 aphillips

Closing resolve-candidates per discussion in 2023-07-24 call

aphillips avatar Jul 29 '23 16:07 aphillips