Localization

From moasq/nanowave · View interactive version

Localization is an AI agent skill from the GitHub repository moasq/nanowave. Localization patterns: .strings file generation, RTL/LTR layout, language switching, locale-aware formatting. Use when implementing app features related to localization.

How to use this skill

Skill file

Localization

LOCALIZATION (.strings files + RTL/LTR + Language Switching):

FORBIDDEN PATTERNS (CRITICAL — violation = broken app):

if appLanguage == "ar" { Text("الإعدادات") } else { Text("Settings") }

switch language { case "ar": return "بحث" default: return "Search" }

.strings FILE GENERATION:

CRITICAL — localization key usage rules:

Rule 1 — String LITERALS in views are auto-localized:

Text("settings_title"), .navigationTitle("dashboard_title"), Label("tab_workouts", systemImage: "icon")

SwiftUI treats these as LocalizedStringKey and looks them up using the environment locale.

Rule 2 — String VARIABLES are NOT auto-localized:

let key = "settings_title"; Text(key) — shows raw key text. This is the #1 localization bug.

FIX: Text(LocalizedStringKey(key))

Rule 3 — Computed properties returning keys for display:

If a switch/computed property returns a key as String (e.g. "metric_steps"), and you pass it to Text(label), it will NOT be localized.

FIX: Return LocalizedStringKey instead of String from the computed property.

Rule 4 — NEVER use String(localized:) in view parameters:

Text(String(localized: "key")) resolves against SYSTEM locale, NOT the environment locale. Runtime language switching breaks.

Rule 5 — EVERY key in code must exist in EVERY .strings file. Missing key = raw key shown to user.

CONFIG_CHANGES FOR LOCALIZATIONS:

LANGUAGE SELECTION & SWITCHING:

private var layoutDirection: LayoutDirection {

["ar", "he", "fa", "ur"].contains(appLanguage) ? .rightToLeft : .leftToRight

}

RootView()

.id(appLanguage) // MANDATORY: forces full view rebuild on language change

.environment(\.locale, Locale(identifier: appLanguage))

.environment(\.layoutDirection, layoutDirection)

RTL / LTR LAYOUT DIRECTION:

LOCALE-AWARE FORMATTING:

TESTING RTL IN PREVIEWS:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.