Giter VIP home page Giter VIP logo

localize-xibs's Introduction

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)

localize-xibs's People

Contributors

sergei-dr avatar wvteijlingen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sergei-dr

localize-xibs's Issues

Add default value to translation key

WOuld be nice if a default value could be added to the localization key

t:welcome.main_title:Welcome here

so the generated file would contain
"welcome.main_title" = "Welcome here"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.