Skip to content

Add localization support with JSON resources and Lokalize plugin enhancements#1618

Open
TheBlackBit wants to merge 1 commit intoopenwallet-foundation:mainfrom
TheBlackBit:feat/doctypes-translation
Open

Add localization support with JSON resources and Lokalize plugin enhancements#1618
TheBlackBit wants to merge 1 commit intoopenwallet-foundation:mainfrom
TheBlackBit:feat/doctypes-translation

Conversation

@TheBlackBit
Copy link
Copy Markdown
Contributor

@TheBlackBit TheBlackBit commented Mar 14, 2026

Fixes #1617

Summary

This PR introduces comprehensive localization support for the multipaz-doctypes module and extends the Lokalize plugin with JSON resource format capabilities.

Key Changes

  • Lokalize Plugin: Added JSON format support alongside XML with new generateMultipazStrings task for Kotlin code generation
  • Convention Plugin: Pre-configured defaults for consistent localization across modules
  • Doctypes Localization: Full i18n support with 22 languages for all document types mDL, EU ID, Photo ID, etc.
  • Documentation: Updated READMEs with comprehensive translation instructions

Translation Instructions

For detailed steps on adding new documents and translations, refer to:
multipaz-doctypes/README.md - 4-step process for adding strings
build-logic/lokalize/README.md - Plugin configuration and usage

Test Plan

Run ./gradlew :multipaz-doctypes:lokalizeCheck to verify translations
Run ./gradlew :multipaz-doctypes:generateMultipazStrings to generate code
Build and test on Android, iOS, and JVM targets
Verify localized strings display correctly in sample app
IMG_0009
Screenshot_1773519817

  • Tests pass
  • Appropriate changes to README are included in PR
Copy link
Copy Markdown
Contributor

@dzuluaga dzuluaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on the localization infrastructure! I have a few findings below — 2 bugs, 1 legal fix, and 1 design question.

* First the attributes that the mDL and VC Credential Type have in common
*/
.addMdocAttribute(
DocumentAttributeType.String,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design question: getDocumentType() now calls LocalizedStrings.getString() ~80 times, and each call invokes NativeLocale.currentLocale() (which hits platform locale APIs). Previously these were static English strings.

A few implications worth considering:

  • Performance: Every getDocumentType() call does ~80 platform locale lookups + ~80 map lookups. If these are called frequently, it could add up.
  • Consistency: If the device locale changes between two calls to getDocumentType(), you'd get different results. And since DrivingLicense is an object, callers might not expect the output to vary.
  • Singleton caching: If anyone caches the result of getDocumentType(), they'll get strings frozen in whatever locale was active at cache time.

This may all be fine for the current use case — just flagging it as a behavioral change from the previous static-string approach.

Copy link
Copy Markdown
Contributor Author

@TheBlackBit TheBlackBit Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right @dzuluaga that LocalizedStrings.getString() currently resolves NativeLocale.currentLocale() on every lookup, and getDocumentType() performs many lookups, so this introduces repeated locale/API calls and locale-dependent output across invocations. For current usage this is likely acceptable, but it’s still unnecessary overhead and less deterministic than before.
I’ll follow up with a small optimization: resolve locale once per getDocumentType() call and pass that locale through string lookups, so we avoid repeated platform locale reads while preserving dynamic localization behavior. I’ll hold off on DocumentType caching for now unless profiling shows rebuild cost is significant.

@TheBlackBit TheBlackBit force-pushed the feat/doctypes-translation branch 2 times, most recently from be00338 to 8973532 Compare March 17, 2026 05:49
@TheBlackBit TheBlackBit requested a review from dzuluaga March 17, 2026 05:52
@TheBlackBit TheBlackBit force-pushed the feat/doctypes-translation branch from 8973532 to 6b8cf47 Compare March 17, 2026 06:16
Copy link
Copy Markdown
Contributor

@dzuluaga dzuluaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Ever, LGTM! 👍

@davidz25
Copy link
Copy Markdown
Contributor

This looks like a great start 🚀 - added a couple of comments!

@TheBlackBit TheBlackBit force-pushed the feat/doctypes-translation branch from 6b8cf47 to d318b78 Compare March 18, 2026 23:12
@TheBlackBit TheBlackBit requested a review from davidz25 March 18, 2026 23:14
…kalize plugin

This commit introduces comprehensive localization support for the multipaz-doctypes
module and extends the Lokalize plugin with JSON resource format capabilities.

Key Changes:

1. Lokalize Plugin Enhancements:
   - Added JSON resource format support alongside existing XML format
   - New outputFormat configuration option (XML or JSON)
   - Implemented JsonResourceScannerStrategy and JsonResourceWriterStrategy
   - Added ResourceScannerStrategyFactory and ResourceWriterStrategyFactory for
     pluggable format handling
   - New generateMultipazStrings task for Kotlin code generation from JSON resources
   - Supports code generation for platforms with unreliable file access (iOS)
   - Added OutputFormat enum for format selection

2. Lokalize Convention Plugin:
   - Created convention plugin for pre-configured defaults
   - Applied common settings: defaultLocale="en", 22 target locales
   - Configured Google Gemini as default LLM provider

3. Multipaz Doctypes Localization:
   - Added StringKeys object with compile-time safe string constants
   - Implemented LocalizedStrings for runtime string lookup
   - Created NativeLocale expect/actual for platform-specific locale detection
   - Added JSON translation files for 22 languages:
     Arabic, Czech, Danish, German, Greek, Spanish, French, Hebrew, Hindi,
     Indonesian, Italian, Japanese, Korean, Dutch, Polish, Portuguese,
     Russian, Thai, Turkish, Ukrainian, Vietnamese, Chinese (Simplified)
   - Updated all document types (DrivingLicense, EUPersonalID, etc.) to use
     localized strings for display names and descriptions

4. Build Configuration:
   - Configured multipaz-doctypes to use JSON output format
   - Set resourcesDir to src/commonMain/resources
   - Integrated generateMultipazStrings for code generation

5. Testing:
   - Added LocalizedStringsTest and NativeLocaleTest for commonTest

Updated README files to document the new JSON format and code generation features.

Signed-off-by: Ever Morales <ever.morales@koombea.com>
@TheBlackBit TheBlackBit force-pushed the feat/doctypes-translation branch from d318b78 to 3a9eacf Compare March 19, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants