/Localize

🏁 Automatically clean your Localizable.strings files

Primary LanguageSwiftMIT LicenseMIT

Localize

Localize

Language: Swift Platform: iOS codebeat badge License: MIT Release version

Localize is a tiny run script that keeps your Localizable.strings files clean and emits warnings when something is suspicious.

Localize

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.

Try it!

Localize is part of freshOS iOS toolset. Try it out in the included example app!

How

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.

What

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

Installation

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/

Configuration

Configure the top section of the Localize.swift according to your project.

More

Ignore [Potentially Untranslated] warnings

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

Unused false positive

Not found by the script reason 1

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+)\""
]

Not found by the script reason 2

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"
]

Author

Sacha Durand Saint Omer, sachadso@gmail.com

Contributors

JuliusBahr, ezisazis, michalsrutek

Contributing

Contributions to Localize are very welcomed and encouraged!

License

Localize is available under the MIT license. See LICENSE for more information.

Backers

Like the project? Offer coffee or support us with a monthly donation and help us continue our activities :)

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site :)