korge
korge copied to clipboard
Translate ordinals (1st, 2nd...) into several languages [de, es, fr, it, ja, ko, nb, nl, pt, ru, sv, uk, zh]
https://github.com/korlibs/klock/blob/ca25e8a8b7d8ed2acefda96678331471b546b32b/klock/src/commonMain/kotlin/com/soywiz/klock/KlockLocale.kt#L20-L33
https://github.com/korlibs/klock/issues/150
- [x] English - Initial - https://github.com/korlibs/klock/pull/152
- [x] German
- [ ] Spanish
- [ ] French
- [ ] Italian
- [ ] Japanese
- [ ] Korean
- [ ] Norwegian
- [ ] Dutch
- [ ] Portuguese
- [x] Russian
- [ ] Swedish
- [ ] Ukrainian
- [ ] Chinese
Hey @soywiz, it's not quite easy for example for Russian because the ending of an ordinal depends on the gender of the word after it.
For example: let's take two words with different gender:
language | boy | girl |
---|---|---|
Eng | 1st | 1st |
Eng | 20th | 20th |
Rus | 1-й | 1-я |
Rus | 20-й | 20-я |
Reference: https://en.wikipedia.org/wiki/Ordinal_indicator#Russian
Maybe for some other languages the same is true. So how we should solve it?
I see. I was not aware of that! We could provide something like LocaleContext, and then populate it with extra information, like gender or other stuff, so it is extensible to support several languages and we don't have to hardcode them for parameters.
But first of all, this library is just for dates, and there is no Locale concept in the Kotlin standard library just yet:
Do date numbers 1-31 in Russian have gender? Boy/girl? If so, are they static depending on the specific day, or could both be supported.
In the end the current signature: open fun getOrdinalByDay(day: Int): String
could work?
Do date numbers 1-31 in Russian have gender?
Which exactly "date numbers"? I've just come up with two variants and realized that we also use the suffix of neuter gender sometimes for ordinals in Russian 😅
language | day of month (like "boy", example: 1st day of month ) |
of MONTH_NAME (neuter gender, example: the 1st of January ) |
---|---|---|
Eng | 1st | 1st |
Eng | 20th | 20th |
Rus | 1-й | 1-е |
Rus | 20-й | 20-е |
So I need to know in which sentence the result of getOrdinalByDay
is used... This method can't cover all the cases in the current state. However, if it's meant to cover only the specific case, then it's possible, please give me an example of this specific case.
~~The third variant uses feminine gender:~~
~~language~~ | ~~date (like "girl", example: 1st date )~~ |
---|---|
~~Eng~~ | ~~1st~~ |
~~Eng~~ | ~~20th~~ |
~~Rus~~ | ~~1-я~~ |
~~Rus~~ | ~~20-я~~ |
~~So all genders of Russian language are possible for "date numbers", unless you define them more strictly.~~
UPD: realized that it seems it's not the case for 1..31 ordinals, because a date is another thing, we can easily say for example 100th date. So please forget about date :)
Would this work for you?
class KlockLocalContext(...)
fun KlockLocalContext.withGender(gender: KlockLocaleGender): KlockLocalContext
enum class KlockLocaleGender {} // What about non-binary, etc.? Are used in any supported language?
open fun getOrdinalByDay(day: Int, context: KlockLocalContext = EmptyKlockLocalContext): String
Edit: so in the end is it required for Klock?
Still this discussion could help if someone is making or willing to make a Locale library, or if the Kotlin team plans to add Locale support to the std library at some point
Edit: so in the end is it required for Klock?
Yep, for Russian two genders of ordinals seem to be used in "date numbers": masculine and neuter.
Would this work for you?
Seems like it will work for Russian. I can try opening a PR for KlockLocaleGender, KlockLocalContext, and Russian ordinals. OK?
What about non-binary, etc.? Are used in any supported language?
Just a wild guess: dates appeared in languages quite long ago so there are no dates with non-binary gender in different languages. Of course I can be wrong, but I think other genders can be added later if needed
Sure. Feel free to open a PR. Additionally, could you ask someone from Russia to review the PR too when available?
So korlibs/korge-next#191 is merged, a tick can be placed here 😉
- [x] Russian - korlibs/korge-next#191
Done! It will be available on next version once I integrate changes from korge-next
Hi @soywiz I wanted to push a branch for the german ordinals, but I am not allowed. Do you need to grant me rights?
Hi @soywiz I wanted to push a branch for the german ordinals, but I am not allowed. Do you need to grant me rights?
Hey @Bantolomeus you have to fork this repository, push the changes in your fork and make a PR with the changes