diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index eff0cd2..25fcac6 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -12,7 +12,7 @@ "name": "pdat-swift-practice", "source": "./pdat-swift-practice", "description": "Curated Apple platform findings with sources, plus practices learned from production incidents.", - "version": "0.5.0", + "version": "0.6.0", "author": { "name": "PDAT s.r.o." }, diff --git a/pdat-swift-practice/.claude-plugin/plugin.json b/pdat-swift-practice/.claude-plugin/plugin.json index d22eb46..f1b9f53 100644 --- a/pdat-swift-practice/.claude-plugin/plugin.json +++ b/pdat-swift-practice/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "pdat-swift-practice", - "version": "0.5.0", + "version": "0.6.0", "description": "Curated Apple platform findings with sources, plus practices learned from production incidents.", "author": { "name": "PDAT s.r.o.", diff --git a/pdat-swift-practice/skills/apple-findings/references/localization.md b/pdat-swift-practice/skills/apple-findings/references/localization.md index 5317038..86ba5cf 100644 --- a/pdat-swift-practice/skills/apple-findings/references/localization.md +++ b/pdat-swift-practice/skills/apple-findings/references/localization.md @@ -43,6 +43,31 @@ count wrapped in parentheses — "Send unsent receipts (3)" — dodges the problem entirely and is a reasonable fallback where a plural form would be awkward. +## Testing a translation needs the right bundle, not the right locale + +`String(localized:locale:)` looks like it renders a given language. It does +not: `locale:` drives number and date formatting, while the language comes +from the **bundle**. A test that passes `locale: Locale(identifier: "cs")` +and nothing else reads the English strings and reports them as if they +were Czech. + +```swift +let path = Bundle.main.path(forResource: "cs", ofType: "lproj")! +let czech = Bundle(path: path)! +String(localized: "\(1) coupons", bundle: czech, locale: Locale(identifier: "cs")) +``` + +Our first attempt at the plural test got this wrong and failed with +`"1 coupon" == "1 kupón"` — which at a glance reads as "the plurals are +broken" when in fact the English plurals were working and the test was +looking in the wrong place. + +Also: a plural variation must reference the number. A key extracted as +`%@ coupons` cannot carry one, and the build fails outright with "Plural +variation requires referencing the number in the string" — usable +feedback, and a reason to keep counts typed as `Int` so the key comes out +as `%lld`. + **Step forward?** Yes, and overdue. This is the kind of defect that never shows up in a test and that a Czech speaker notices immediately.