Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate ordinals (1st, 2nd...) into several languages [de, es, fr, it, ja, ko, nb, nl, pt, ru, sv, uk, zh] #153

Open
2 of 14 tasks
soywiz opened this issue Nov 8, 2020 · 9 comments

Comments

@soywiz
Copy link
Member

@soywiz soywiz commented Nov 8, 2020

open val ordinals = Array(32) {
if (it in 11..13) {
"${it}th"
} else {
when (it % 10) {
1 -> "${it}st"
2 -> "${it}nd"
3 -> "${it}rd"
else -> "${it}th"
}
}
}
open fun getOrdinalByDay(day: Int): String = ordinals[day]

#150

  • English - Initial - #152
  • German
  • Spanish
  • French
  • Italian
  • Japanese
  • Korean
  • Norwegian
  • Dutch
  • Portuguese
  • Russian
  • Swedish
  • Ukrainian
  • Chinese
@soywiz soywiz added this to Backlog in Korlibs via automation Nov 8, 2020
@soywiz soywiz moved this from Backlog to Hanging fruits / Nice 1st contrib in Korlibs Nov 8, 2020
@soywiz soywiz changed the title Translate ordinals into spanish Translate ordinals into several languages Nov 8, 2020
@soywiz soywiz changed the title Translate ordinals into several languages Translate ordinals into several languages [de, es, fr, it, ja, ko, nb, nl, pt, ru, sv, uk, zh] Nov 8, 2020
@soywiz soywiz changed the title Translate ordinals into several languages [de, es, fr, it, ja, ko, nb, nl, pt, ru, sv, uk, zh] Translate ordinals (1st, 2nd...) into several languages [de, es, fr, it, ja, ko, nb, nl, pt, ru, sv, uk, zh] Nov 11, 2020
@SerVB
Copy link

@SerVB SerVB commented Mar 5, 2021

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?

@soywiz
Copy link
Member Author

@soywiz soywiz commented Mar 5, 2021

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?

@SerVB
Copy link

@SerVB SerVB commented Mar 5, 2021

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.

@SerVB
Copy link

@SerVB SerVB commented Mar 5, 2021

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 :)

@soywiz
Copy link
Member Author

@soywiz soywiz commented Mar 5, 2021

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

@SerVB
Copy link

@SerVB SerVB commented Mar 5, 2021

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

@soywiz
Copy link
Member Author

@soywiz soywiz commented Mar 5, 2021

Sure. Feel free to open a PR. Additionally, could you ask someone from Russia to review the PR too when available?

SerVB added a commit to SerVB/korge-next that referenced this issue Mar 6, 2021
soywiz added a commit to korlibs/korge-next that referenced this issue Apr 2, 2021
@SerVB
Copy link

@SerVB SerVB commented Apr 4, 2021

So korlibs/korge-next#191 is merged, a tick can be placed here 😉

- [x] Russian - korlibs/korge-next#191

@soywiz
Copy link
Member Author

@soywiz soywiz commented Apr 4, 2021

Done! It will be available on next version once I integrate changes from korge-next

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Korlibs
Nice 1st contrib / Help wanted
Development

No branches or pull requests

3 participants
@soywiz @SerVB and others