localization-patterns
Skill66 starsChanged 6 months agoMITView on GitHub
Localization patterns for mobile - string resources, plurals, RTL support, Compose localization, KMP shared strings, and locale management.
In this repository51 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rules/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- examples/CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/everything-mobile.mdcCursor rule
- accessibility-patternsSkill
- analytics-patternsSkill
- android-patternsSkill
- app-lifecycleSkill
- ci-cd-patternsSkill
- combine-frameworkSkill
- continuous-learningSkill
- continuous-learning-v2Skill
- core-dataSkill
- coroutines-patternsSkill
- deep-linkingSkill
- expect-actualSkill
- feature-builderSkill
- feature-flagsSkill
- gradle-patternsSkill
- image-loadingSkill
- ios-testingSkill
- jetpack-composeSkill
- kmp-diSkill
- kmp-navigationSkill
- kmp-networkingSkill
- kmp-repositoriesSkill
- koin-patternsSkill
- ktor-patternsSkill
- liquid-glassSkill
- m3-expressiveSkill
- mobile-checkpointSkill
- mobile-compactionSkill
- mobile-instinct-v1Skill
- mobile-instinct-v2Skill
- mobile-memorySkill
- mobile-securitySkill
- mobile-testingSkill
- mobile-verificationSkill
- mvi-architectureSkill
- navigation-composeSkill
- offline-firstSkill
- pagination-patternsSkill
- push-notificationsSkill
- room-patternsSkill
- shared-coroutinesSkill
- shared-modelsSkill
- sqldelight-patternsSkill
- swift-patternsSkill
- swiftui-patternsSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 341
Create values-en-rXA/strings.xml (pseudo-locale) to test text expansion.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Localization Patterns for Mobile
Android
strings.xml Resources
<!-- res/values/strings.xml (default - English) -->
<resources>
<string name="app_name">MyApp</string>
<string name="welcome_message">Welcome, %1$s!</string>
<string name="price_format">%1$s %2$.2f</string>
<string-array name="categories">
<item>Electronics</item>
<item>Clothing</item>
<item>Books</item>
</string-array>
<plurals name="items_count">
<item quantity="zero">No items</item>
<item quantity="one">%d item</item>
<item quantity="other">%d items</item>
</plurals>
</resources>
<!-- res/values-es/strings.xml (Spanish) -->
<resources>
<string name="app_name">MiApp</string>
<string name="welcome_message">Bienvenido, %1$s!</string>
<plurals name="items_count">
<item quantity="one">%d elemento</item>
<item quantity="other">%d elementos</item>
</plurals>
</resources>
<!-- res/values-ar/strings.xml (Arabic - RTL) -->
<resources>
<string name="welcome_message">%1$s ,مرحبًا</string>
<plurals name="items_count">
<item quantity="zero">لا عناصر</item>
<item quantity="one">عنصر واحد</item>
<item quantity="two">عنصران</item>
<item quantity="few">%d عناصر</item>
<item quantity="many">%d عنصرًا</item>
<item quantity="other">%d عنصر</item>
</plurals>
</resources>String Formatting with Arguments
// Positional arguments: %1$s = first string, %2$d = second integer
// strings.xml: <string name="greeting">Hello %1$s, you have %2$d new messages</string>
val formatted = context.getString(R.string.greeting, userName, messageCount)
// Plurals
val itemsText = context.resources.getQuantityString(
R.plurals.items_count,
count, // quantity selector
count // format argument
)Compose Localization
@Composable
fun WelcomeScreen(userName: String, itemCount: Int) {
Column {
Text(text = stringResource(R.string.welcome_message, userName))
Text(text = pluralStringResource(R.plurals.items_count, itemCount, itemCount))
}
}Per-App Language Preference (API 33+)
// AndroidManifest.xml
<application android:localeConfig="@xml/locales_config" ...>
// res/xml/locales_config.xml
<?xml version="1.0" encoding="utf-8"?>
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
<locale android:name="en" />
<locale android:name="es" />
<locale android:name="ar" />
<locale android:name="ja" />
</locale-config>// Programmatic language change
val localeManager = context.getSystemService(LocaleManager::class.java)
localeManager.applicationLocales = LocaleList(Locale.forLanguageTag("es"))
// For pre-API 33 with AppCompat
AppCompatDelegate.setApplicationLocales(
LocaleListCompat.forLanguageTags("es")
)RTL Layout Support
<!-- AndroidManifest.xml -->
<application android:supportsRtl="true" ...>
<!-- Use start/end instead of left/right -->
<TextView
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:paddingStart="12dp"
android:textAlignment="viewStart" />// Compose RTL
@Composable
fun AdaptiveLayout() {
val layoutDirection = LocalLayoutDirection.current
val isRtl = layoutDirection == LayoutDirection.Rtl
Row(
modifier = Modifier.padding(start = 16.dp, end = 8.dp)
// start/end automatically flip in RTL
) {
Icon(
imageVector = if (isRtl) Icons.Default.ArrowBack else Icons.Default.ArrowForward,
contentDescription = null
)
Text(text = stringResource(R.string.next))
}
}iOS
Localizable.strings
/* Localizable.strings (English) */
"app_name" = "MyApp";
"welcome_message" = "Welcome, %@!";
"price_format" = "%@ %.2f";
"settings_title" = "Settings";/* Localizable.strings (Spanish) */
"app_name" = "MiApp";
"welcome_message" = "Bienvenido, %@!";
"settings_title" = "Configuración";String Catalogs (.xcstrings - Xcode 15+)
Xcode 15 introduces String Catalogs (.xcstrings) as a single JSON file replacing .strings and .stringsdict. Xcode auto-extracts localizable strings from code and manages translations in one place.
String(localized:) and NSLocalizedString
// Modern (iOS 16+)
let welcome = String(localized: "welcome_message")
// With arguments
let greeting = String(localized: "Welcome, \(userName)!")
// Legacy
let title = NSLocalizedString("settings_title", comment: "Title for settings screen")SwiftUI Text with LocalizedStringKey
struct WelcomeView: View {
let userName: String
var body: some View {
VStack {
// Automatically uses Localizable.strings
Text("settings_title")
// With interpolation
Text("Welcome, \(userName)!")
// Explicit localized key
Text(LocalizedStringKey("welcome_message"))
}
}
}Plural Rules with .stringsdict
<!-- Localizable.stringsdict -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ...>
<plist version="1.0">
<dict>
<key>items_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@count@</string>
<key>count</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>zero</key>
<string>No items</string>
<key>one</key>
<string>%d item</string>
<key>other</key>
<string>%d items</string>
</dict>
</dict>
</dict>
</plist>let text = String(format: NSLocalizedString("items_count", comment: ""), itemCount)RTL Support in SwiftUI
struct AdaptiveRow: View {
@Environment(\.layoutDirection) var layoutDirection
var body: some View {
HStack {
// leading/trailing automatically respect RTL
Text("Label")
Spacer()
Image(systemName: layoutDirection == .rightToLeft
? "chevron.left" : "chevron.right")
}
.padding(.leading, 16)
.padding(.trailing, 8)
}
}KMP Shared Strings
Common Interface with expect/actual
// commonMain
expect class StringProvider {
fun getString(key: String): String
fun getString(key: String, vararg args: Any): String
fun getPluralString(key: String, quantity: Int, vararg args: Any): String
}
// androidMain
actual class StringProvider(private val context: Context) {
actual fun getString(key: String): String {
val resId = context.resources.getIdentifier(key, "string", context.packageName)
return if (resId != 0) context.getString(resId) else key
}
actual fun getString(key: String, vararg args: Any): String {
val resId = context.resources.getIdentifier(key, "string", context.packageName)
return if (resId != 0) context.getString(resId, *args) else key
}
actual fun getPluralString(key: String, quantity: Int, vararg args: Any): String {
val resId = context.resources.getIdentifier(key, "plurals", context.packageName)
return if (resId != 0) context.resources.getQuantityString(resId, quantity, *args) else key
}
}
// iosMain
actual class StringProvider {
actual fun getString(key: String): String {
return NSBundle.mainBundle.localizedStringForKey(key, value = key, table = null)
}
actual fun getString(key: String, vararg args: Any): String {
val template = getString(key)
return String.format(template, *args)
}
actual fun getPluralString(key: String, quantity: Int, vararg args: Any): String {
val template = getString(key)
return String.format(template, *args)
}
}moko-resources Library Pattern
// build.gradle.kts
commonMain {
dependencies {
implementation("dev.icerock.moko:resources:0.23.0")
}
}
// commonMain/resources/MR/base/strings.xml
// commonMain/resources/MR/es/strings.xml
// Access: MR.strings.welcome_message.getString()Testing
Pseudo-Localization
Android: Enable in Developer Options > "Force pseudo-locales" to test with accented characters and RTL wrapping.
# Force locale on Android emulator
adb shell settings put system user_locale "ar-SA"
adb shell am restartLayout Testing with Long Strings
Create values-en-rXA/strings.xml (pseudo-locale) to test text expansion. German and Finnish text is typically 30-40% longer than English.
// Compose UI test with locale
@Test
fun testLongTextLayout() {
composeTestRule.setContent {
CompositionLocalProvider(
LocalConfiguration provides Configuration().apply {
setLocale(Locale("de"))
}
) {
WelcomeScreen(userName = "Maximilian Schwarzenegger")
}
}
// Verify no text truncation or overflow
}Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

