aminography / PrimeDatePicker

PrimeDatePicker is a tool that provides picking a single day, multiple days, and a range of days.
Apache License 2.0
471 stars 52 forks source link

Wrong month cases for Russian\Ukranian languages #75

Open akaish opened 1 year ago

akaish commented 1 year ago

Hello, I'm working on app that targeted to Russian\Ukrainian\Belarus audience and noticed that when phone language is Russian month names in picker are in wrong case. In some languages word spelling differs depends on context, it is called cases. I don't mean upper\lower case.

For example, "марта 2023" instead of "март 2023" (March 2023). When you want month name of a year, you spell it in nominative case (март 2023), however when subject is day than month in genitive (16 марта 2023).

I assume that the problem in date utils you are using as dependency for prime calendar, it returns month name cut from full date string (for example for date "16 марта 2023" when you calls smth like date.month.name it returns month name in genitive). I assume, that this issue can be in all languages with cases (word spelling differs depends on context). Actually I have now idea, how to fix it properly, I've just used durty hack (tested on Russian locale, same would do for other Slavic languages):

class RUMonthNameSpellFix {
    companion object {
        private val namesMapRU = HashMap<String, String>().apply {
            put("марта", "март")
            put("апреля", "апрель")
            put("мая", "май")
            put("июня", "июнь")
            put("июля", "июль")
            put("августа", "август")
            put("сентября", "сентябрь")
            put("октября", "октябрь")
            put("ноября", "ноябрь")
            put("декабря", "декабрь")
            put("января", "январь")
            put("февраля", "февраль")
        }

        fun applyMonthNameFix(monthName: String, locale: Locale) : String {
            return if(locale.language != "ru") // Russian language ISO 639 code
                monthName
            else {
                namesMapRU[monthName.toLowerCase()] ?: monthName
            }
        }
    }
}

And in com.aminography.primecalendar.civil.CivilCalendar.kt (line 19)

    override val monthName: String
        get() = applyMonthNameFix(internalCalendar.getDisplayName(MONTH, LONG, locale), locale)