Skip to content

Conversation

ionull
Copy link

@ionull ionull commented Oct 9, 2025

Nan is used widely by 46 million people

Describe proposed changes and the issue being fixed

(Optional) Fixes [link to the issue]

Testing

(Optional) Describe how you tested your changes (provide a snippet or/and steps)

(Optional) This should be tested by QA

Release Notes

Section - Subsection

Nan is used widely by 46 million people
@ionull
Copy link
Author

ionull commented Oct 9, 2025

There is some error with the current logic of load plural string, when we add an unknown language like "nan", it fails to load category which cause crash:

// PluralStringResources.kt
private suspend fun loadPluralString(
    resource: PluralStringResource,
    quantity: Int,
    resourceReader: ResourceReader,
    environment: ResourceEnvironment
): String {
    val resourceItem = resource.getResourceItemByEnvironment(environment)
    val item = getStringItem(resourceItem, resourceReader) as StringItem.Plurals
    val pluralRuleList = PluralRuleList.getInstance(
        environment.language,
        environment.region,
    )
    // pluralRuleList is empty, pluralRuleList.getCategory(quantity) will crash
    // we'd better check empty status and use item.items[PluralCategory.OTHER]
    val pluralCategory = pluralRuleList.getCategory(quantity)
    val str = item.items[pluralCategory]
        ?: item.items[PluralCategory.OTHER]
        ?: error("Quantity string ID=`${resource.key}` does not have the pluralization $pluralCategory for quantity $quantity!")
    return str
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant