-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support plural string resource #4519
Conversation
@paxbun Thank you for the great contribution! I made a backward PR to your branch with some refactorings. And I would like to ask to change a logic a bit: not to crash an app when user hasn't provided any pluralization: kotlin.IllegalStateException: String ID=`new_message` does not have the pluralization MANY for quantity 0! I guess it's better to use a some default and print a warning to the log. what do you think? |
@terrakok Thanks for the comment! I merged your changes and renamed the properties of GeneratePluralRuleListsTask (cause they're now files, not directories).
The current implementation of Android SDK also throws an Exception when there is no proper pluralization, although mine did not fallback to We can return an empty string, but in that case we also have to care about ones with format arguments because |
The reason of the red tests is the compose gradle plugin uses published version, which doesn't have the PluralResource yet. We have to divide the PR on two:
|
I will do it manually |
BTW, you forgot to val pluralCategory = PluralCategory.fromString(
element.getAttribute("quantity"),
) ?: return@mapNotNull null
val rawString = element.textContent.orEmpty()
pluralCategory to handleSpecialCharacters(rawString) // <--- here
could you fix it? |
Of course! Here is the PR as you requested: #4543 |
A follow-up PR for #4519, which handles special characters for quantity strings.
Ports a part of Unicode's ICU in pure Kotlin and implements Android-style plural string resource support. Fixes #425.
Changes
org.jetbrains.compose.resources.intl.{PluralCategory, PluralRule, PluralRuleList}
, which parses and evaluates scripts in Unicode's Locale Data Markup Langauge.plurals.xml
from Unicode's CLDR.GeneratePluralRuleListsTask
, which parsesplurals.xml
and generates required Kotlin source codes.PluralStringResource
,pluralStringResource
, orgetPluralString
, corresponding toStringResource
,stringResource
, orgetString
.ResourcesSpec.kt
so the generatedRes
class exposesRes.plurals
.Potential Further Improvements
compose.resources {}
block ([gradle] Add DSL to configure compose resources #4482) to determine the default pluralization rule (or just presume English as default)Res
only for languages used incomposeResources