Skip to content

Added string pluralization support#102

Merged
marcprux merged 4 commits intoskiptools:mainfrom
fhasse95:String-Pluralization-Support
Mar 14, 2026
Merged

Added string pluralization support#102
marcprux merged 4 commits intoskiptools:mainfrom
fhasse95:String-Pluralization-Support

Conversation

@fhasse95
Copy link
Contributor

@fhasse95 fhasse95 commented Mar 14, 2026

This PR adds string pluralization support by reading out all .stringsdict files in Bundle.swift and converting their contents into ICU MessageFormat strings within PropertyListSerialization.swift. These strings are then stored in the existing localizedTables mapping, allowing String.localizedStringWithFormat to leverage the native MessageFormat on Android, which ensures that plural rules are resolved correctly according to the user's locale.

To try it out, you can check out the updated LocalizationPlayground in Skip Showcase.

Related PR:

Notes & Limitations:

  • Please note that specific forms like "few" or "many" will only trigger if the device itself is set to a locale that supports them (e.g., Ukrainian). Consequently, if a string is formatted using a custom locale that requires additional grammatical forms (like in LocalizationPlayground.swift), these may not be correctly applied if the underlying system locale is set to a language like English, which only supports "one" and "other". However, since users typically have their devices set to their native locale, and this behavior is consistent with Apple's documentation for localizedStringWithFormat, I believe this limitation is negligible in practice.
  • Also, if you might ask why I used localizedStringWithFormat, it is because as far as I understood it, constructors like String(format:locale:arguments:) are not supported in Skip since it does not wrap Kotlin's primitive types (see Skip Docs). Therefore, I made the decision to use the localizedStringWithFormat function instead to be able to archive the pluralization support.

Thank you for contributing to the Skip project! Please use this space to describe your change and add any labels (bug, enhancement, documentation, etc.) to help categorize your contribution.

Please review the contribution guide at https://skip.dev/docs/contributing/ for advice and guidance on making high-quality PRs.

Skip Pull Request Checklist:

  • REQUIRED: I have signed the Contributor Agreement
  • REQUIRED: I have tested my change locally with swift test
  • OPTIONAL: I have tested my change on an iOS simulator or device
  • OPTIONAL: I have tested my change on an Android emulator or device

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.
    => I used AI assistance while creating the ICU conversion. I manually verified the changes using Skip Showcase and my own app, and at least all of my *.stringsdict files functioned as expected on both platforms.

@marcprux
Copy link
Member

@fhasse95
Copy link
Contributor Author

Could we get some tests in https://github.com/skiptools/skip-foundation/blob/main/Tests/SkipFoundationTests/Foundation/LocaleTests.swift?

Yes, I’ve added some test cases to verify the parsing and formatting of .stringsdict files 👍🏻

@marcprux
Copy link
Member

This is a great feature! Thanks very much!

@marcprux marcprux merged commit 9001996 into skiptools:main Mar 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants