Skip to content

LocalizeKit runtime hardening: SafeFormat crash-safety, plural/locale fixes, and cleanup - #28

Merged
ImaginativeShohag merged 9 commits into
over-the-air-translation-updatefrom
localizekit-safeformat-and-plural-fixes
Sep 26, 2026
Merged

ImaginativeShohag merged 9 commits into
over-the-air-translation-updatefrom
localizekit-safeformat-and-plural-fixes

Conversation

@Md-Saifullah

Copy link
Copy Markdown
Collaborator

Summary

Hardens the LocalizeKit runtime with crash-safety fixes, correct locale-aware
plural resolution, and supporting refactors/test cleanup.

Fixes

  • SafeFormat vs NSNumber: reject genuine NSNumber (incl. NSDecimalNumber) for non-%@ specifiers — it satisfies is Int/is Double but is encoded as an object pointer, so %d/%f would
    print garbage.
  • Malformed percent specifiers: surface as ambiguous and fall back to the verbatim string instead of mangling output — trailing bare %, positional index too large for Int, and specifiers
    truncated before their conversion char.
  • Plural fallback locale: resolve the default-plural CLDR category from the app's selected language (currentLanguageCode), not the device locale (a French device on an English app no longer picks
    French plural forms).
  • Int.min trap: guard plural-category resolution against Int.min (abs() would trap).

Features

  • Add country-scoped language(code:in:) lookup to avoid nondeterministic matches across countries sharing a code.

Refactors

  • Rename currentLanguage → currentLanguageCode for clarity across call sites and docs.
  • Simplify storage clear-all and cache-state paths.
  • Move Store's inline LocalizationAPI stubs into bundled mock JSON fixtures.

Tests / chore

  • Standardize test naming to test_when_should, correct the misleading SafeFormat mismatch test, and reset the shared LocalizationManager language in setUp for determinism.
  • New coverage for NSNumber, malformed-specifier fallbacks, and the French plural regression.
  • Update resolved dependency versions.

Clarify that the property holds a language code (e.g. "en", "fr_FR"), not a display name. Update all call sites and docs accordingly.
…cases

Guard the plural-category resolution against Int.min (abs() would trap) and collapse the duplicated CLDR branches into shared cases.
Streamline the clear-all and cache-state logic in the storage layer.
…ecifiers

Reject genuine NSNumber (incl. NSDecimalNumber) for non-%@ specifiers: it satisfies `is Int`/`is Double` but is encoded as an object pointer, so %d/%f would read pointer bits and
  print garbage.

Surface malformed percent sequences as ambiguous so SafeFormat degrades to the verbatim string instead of silently mangling output: trailing bare `%` at end-of-string, positional index
  too large to fit in Int, and specifiers truncated before their conversion character.

Add coverage and performance cases for the new fallback paths.
…ce locale

The default-plural fallback resolved the CLDR category from the device locale, so a French device running the app in English would pick French plural forms for the English default
  strings. Resolve the category from the app's selected language (currentLanguageCode) instead.
Resolve a language by code within a specific country's list. The same code can appear under multiple countries with different versions, so resolving against the flattened allLanguages
  would pick a nondeterministic entry.
Adopt the test_when_should naming convention across the localization test suites. Correct the misleading SafeFormat mismatch test (it falls back to the verbatim format rather than
  partially interpolating), add the French default-plural regression test backing the app-language fallback fix, and reset the shared LocalizationManager language in setUp to keep plural resolution
  deterministic across tests.
Extract the inline LocalizationAPI stub data into bundled mock JSON resources for cleaner, more maintainable fixtures.
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: c2ef60d0-6195-4678-abf9-7de4b37b4b9b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ImaginativeShohag
ImaginativeShohag merged commit 9366292 into over-the-air-translation-update Sep 26, 2026
1 of 2 checks passed
@ImaginativeShohag
ImaginativeShohag deleted the localizekit-safeformat-and-plural-fixes branch September 26, 2026 00:23
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.

2 participants