Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
/ localize-xibs Public archive

Easy XIB and Storyboard localization. Reference translations directly from Interface Builder and resolve them at build time.

License

Notifications You must be signed in to change notification settings

wvteijlingen/localize-xibs

Repository files navigation

InstallationUsageUsage as an Xcode Run ScriptCommand line APIProgrammatic API

LocalizeXIBs

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

  1. Keep all your translations in one file per language, instead of different .strings files throughout your project.
  2. Reference your translations directly from Interface Builder, no more dealing with Object ID's.
  3. Immediately get a visual overview of what is translated and what not.
  4. 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.

Installation

mint install wvteijlingen/localize-xibs

Usage

  1. 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.
  2. In the Xcode file inspector, configure your XIBs and Storyboards to be localized using "Localizable Strings".

  3. Wherever you normally enter text using Interface Builder, you can reference your translation using: t:my_translation_key.

  4. 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

Usage as an Xcode Run Script

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

Command line API

localize-xibs [--strict] [--verbose] [<input-files> ...]
  • --strict: Treat warnings as errors.
  • --verbose: Display extra information while processing.

Programmatic API

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)

About

Easy XIB and Storyboard localization. Reference translations directly from Interface Builder and resolve them at build time.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages