Installation • Usage • Usage as an Xcode Run Script • Command line API • Programmatic API
LocalizeXIBs takes the pain out of localizing XIBs and Storyboards, by allowing you to reference translations directly from Interface Builder and resolving them at build time. This means no more dealing with multiple .strings
files that get out of sync, Object IDs, or missing translations at runtime.
It offers the following benefits
- Keep all your translations in one file per language, instead of different
.strings
files throughout your project. - Reference your translations directly from Interface Builder, no more dealing with Object ID's.
- Immediately get a visual overview of what is translated and what not.
- Compile time checking for missing translations.
The biggest problem with the default way of localizing XIBs and Storyboards, is that you have to reference your views from your translation files by Interface Builder Object IDs. LocalizeXIBs flips this around, and allows you to reference your translations from your IB files. This makes for a much better workflow.
mint install wvteijlingen/localize-xibs
-
Add all your translations in centralized
.strings
files in your project, for example:MyProject/Resources/en.lproj/Localizable.strings
MyProject/Resources/de.lproj/Localizable.strings
.
-
In the Xcode file inspector, configure your XIBs and Storyboards to be localized using "Localizable Strings".
-
Wherever you normally enter text using Interface Builder, you can reference your translation using:
t:my_translation_key
. -
In the root of your project run
localize-xibs
, passing it a list of all your centralized translation files. For example:localize-xibs \ MyProject/Resources/en.lproj/Localizable.strings \ MyProject/Resources/de.lproj/Localizable.strings
You can add a Run Script build phase that does the localization for you. That way you can just add translations to your centralized files, and your XIBs and Storyboards will automatically be updated on each build. An added benefit is that it ties in with Xcode, showing you build warnings or errors when you reference a missing translation.
Simply add a Run Script
phase with the localize-xibs command, optionally using the --strict
flag. Make sure it is positioned before the "Copy Bundle Resources" phase.
For example:
localize-xibs --strict \
MyProject/Resources/en.lproj/Localizable.strings \
MyProject/Resources/de.lproj/Localizable.strings
localize-xibs [--strict] [--verbose] [<input-files> ...]
--strict
: Treat warnings as errors.--verbose
: Display extra information while processing.
You can also programmatically use the localize-xibs
package as follows:
import LocalizeXibCore
let translationFiles: Set<String> = [
"MyProject/Resources/en.lproj/Localizable.strings",
"MyProject/Resources/de.lproj/Localizable.strings"
]
let interfaceBuilderFiles: Set<String> = [
"MyProject/Main.storyboard",
"MyProject/SomeViewController.xib",
]
let localizer = Localizer(translationFiles: Set(inputFiles), interfaceBuilderFiles: interfaceBuilderFiles, logger: nil)
let success = localizer.localize(strict: false, verbose: false)