Localize is a tiny run script that keeps your Localizable.strings
files clean and emits warnings when something is suspicious.
Because Localization files tend to rot over time and become a hassle to work with. Stressful when you have to test your app against many different Localizations.
Localize is part of freshOS iOS toolset. Try it out in the included example app!
By using a script running automatically, you have a safety net keeping them sane, checking for translation issues and preventing then to rot over time.
Automatically (On build)
- Cleans you localization files (removes spaces)
- Sorts keys Alphabetically
- Checks for Unused Keys
- Checks for Missing Keys
- Checks for Untranslated (which you can ignore with a flag)
- Checks for Redundant Keys
- Checks for Duplicate Keys
Add the following Run Script
in your project's Build Phases
in XCode, this will run the script at every build.
Use the path of where you copied Localize.swift
script.
${SRCROOT}/{REPLACE ME}} # e.g. ${SRCROOT}/Libs/Localize.swift
Run and Enjoy \o/
Configure the top section of the Localize.swift
according to your project.
Just Add //ignore-same-translation-warning
next to the translation.
Example :
"PhotoKey" = "Photo"; //ignore-same-translation-warning
This will take care of ignoring [Potentially Untranslated] "XXX" in FR file doesn't seem to be localized
The script parses your project sources and checks if your keys are called within NSLocalizedString
calls.
But chances are you have a helper for a shorter NSLocalizedString syntax.
This is indeed supported but you have to give the script what to look for.
You can modify the script to include other ways of localizations:
let patterns = [
"NSLocalizedString\\(@?\"(\\w+)\"", // Swift and Objc Native
"Localizations\\.((?:[A-Z]{1}[a-z]*[A-z]*)*(?:\\.[A-Z]{1}[a-z]*[A-z]*)*)", // Laurine Calls
//Add your own matching regex here
"fsLocalized\\(@?\"(\\w+)\""
]
Another common pattern is to have keys being built at runtime. Of course those keys are not present at compile time so the script can't know about them and emits false positive errors. You can add those keys at the top of of the script to prevent this from happening:
let ignoredFromUnusedKeys = [
"NotificationNoOne",
"NotificationCommentPhoto",
"NotificationCommentHisPhoto",
"NotificationCommentHerPhoto"
]
Sacha Durand Saint Omer, [email protected]
JuliusBahr, ezisazis, michalsrutek
Contributions to Localize are very welcomed and encouraged!
Localize is available under the MIT license. See LICENSE for more information.
Like the project? Offer coffee or support us with a monthly donation and help us continue our activities :)
Become a sponsor and get your logo on our README on Github with a link to your site :)