dart-lang / i18n

A general mono-repo for Dart i18n and l10n packages.
BSD 3-Clause "New" or "Revised" License
62 stars 36 forks source link

Please add locale-specific toUpper/LowerCase #229

Open robertoscaramuzzi opened 6 years ago

robertoscaramuzzi commented 6 years ago

Currently in our project we need to have separate Intl.messages for messages such as 'Paused' and 'PAUSED' because calling Intl.message('Paused').toUpperCase() might be wrong in some languages, namely Turkish, Azeri and Lithuanian.

This introduces the risk that the two messages might be translated differently, introducing confusion for the user.

Note that Intl has toBeginningOfSentenceCase that handles Turkish and Azeri (but not Lithuanian) so this doesn't seem like such a leap.

See http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/65464a307408/src/java.base/share/classes/java/lang/ConditionalSpecialCasing.java

for the OpenJDK implementation (or don't look at it if there are intellectual property issues).

alan-knight commented 6 years ago

What are you asking for this to do? Is it just roughly the equivalent of aString.split("").map((x) => toBeginningOfSentenceCase(x).join(""); perhaps with the addition of Lithuanian? I've been reluctant to do anything that would add a large amount of character data, and the urgent issue seemed to be around these couple of special cases. And you made me worried so I haven't looked at the OpenJDK version.

robertoscaramuzzi commented 6 years ago

Yes, that's what we would need, but likely with some Unicode subtleties that I don't understand.

On Mon, Feb 5, 2018 at 10:40 AM, Alan Knight notifications@github.com wrote:

What are you asking for this to do? Is it just roughly the equivalent of aString.split("").map((x) => toBeginningOfSentenceCase(x).join(""); perhaps with the addition of Lithuanian? I've been reluctant to do anything that would add a large amount of character data, and the urgent issue seemed to be around these couple of special cases. And you made me worried so I haven't looked at the OpenJDK version.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dart-lang/i18n/issues/229, or mute the thread https://github.com/notifications/unsubscribe-auth/AZC77f8x7SiWlOzOJhKuyA8A6CZreKxdks5tR0sogaJpZM4R5r-v .

-- Roberto Scaramuzzi https://www.google.com/+RobertoScaramuzzi

deadsoul44 commented 4 years ago
print(DateFormat('MMMM', 'tr')
        .format(DateTime(2020, 4, 1))
        .split("")
        .map((x) => toBeginningOfSentenceCase(x))
        .join(""));

The code above still prints NISAN instead of NİSAN. Am I missing something?

alan-knight commented 4 years ago

toBeginningOfSentenceCase has an optional locale parameter. If you have not set the default locale to 'tr', then you need to pass that parameter. Also, you don't need to do it for each character, you can just do it for the whole string, skipping the split/join.

deadsoul44 commented 4 years ago

If I skip split/join, it does not work since i is the second letter.

deadsoul44 commented 4 years ago

It is working fine after setting locale. Thank you.

mosuem commented 1 year ago

Implementing this would be quite involved, see the reference implementation at https://icu.unicode.org/design/case/greek-upper. I would be happy to review PRs, if someone would like to attempt this.

mosuem commented 2 weeks ago

@robertbastian it might make sense to expose the ICU4X locale-specific casing as well as the browser version in package:intl4x.