From caa9c781c9b31b72f4b193a45eff32f4e1580e5f Mon Sep 17 00:00:00 2001 From: Jacob Ras Date: Tue, 9 Jan 2024 18:14:27 +0100 Subject: [PATCH] Fall back to English plural rules instead of crashing on unknown locale For many languages this will already be correct and for the ones that needs a custom configuration, at least it won't crash anymore. --- docs/LOCALIZATION.md | 2 ++ .../kotlin/io/github/skeptick/libres/strings/PluralRules.kt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/LOCALIZATION.md b/docs/LOCALIZATION.md index f7e9d49..8f61df4 100644 --- a/docs/LOCALIZATION.md +++ b/docs/LOCALIZATION.md @@ -44,6 +44,8 @@ in JVM 3rd-party library is used. But in Apple this API is closed and in JS it's so to avoid burdening the library with heavy solutions, "out of the box" only rules are provided for [some languages](../libres-core/src/appleAndJsMain/kotlin/io/github/skeptick/libres/strings/PluralRules.kt). +If there are no rules provided for a language, the library falls back to the English rules. + You can create a Pull Request with the required languages or define these values at runtime: ```kotlin diff --git a/libres-core/src/appleAndJsMain/kotlin/io/github/skeptick/libres/strings/PluralRules.kt b/libres-core/src/appleAndJsMain/kotlin/io/github/skeptick/libres/strings/PluralRules.kt index c746c14..2d182ca 100644 --- a/libres-core/src/appleAndJsMain/kotlin/io/github/skeptick/libres/strings/PluralRules.kt +++ b/libres-core/src/appleAndJsMain/kotlin/io/github/skeptick/libres/strings/PluralRules.kt @@ -73,7 +73,7 @@ object PluralRules { "uk" -> Ukrainian "kk" -> Kazakh "fr" -> French - else -> custom[languageCode] ?: error("Plural rule for '$languageCode' not provided") + else -> custom[languageCode] ?: English } }