Giter Site home page Giter Site logo

swiftgenstrings's Introduction

SwiftGenStrings

SwiftGenStrings is a command line application that can be used as a drop-in replacement for the standard genstrings command for Swift sources. The latter only supports the short form of the NSLocalizedString function but breaks as soon as you use any parameters other than key and comment as in

NSLocalizedString("DATE_RANGE", value: "%@ โ€“ %@", comment: "A range of dates")

The upstream issue is tracked here.

Usage

SwiftGenStrings files
SwiftGenStrings [-s <routine>] [-o <outputDir>] files
SwiftGenStrings [-h|--help]

OPTIONS
-h|--help
    (Optional) Print help.
-s routine
    (Optional) Substitute routine for NSLocalizedString, useful when different macro is used.
-o outputDir
    (Optional) Specifies what directory Localizable.strings table is created in.
    Not specifying output directory will print script output content to standard output (console).
files
    List of files, that are used as source of Localizable.strings generation.

To gather strings in current directory, run:

$ find . -name "*.swift" | xargs SwiftGenStrings

If you have any 3rd party code like CocoaPods or Carthage in your project directory, you might want to exclude it from localization. To do that, run the following:

$ find . \( -name "*.swift" ! -path "./Carthage/*" ! -path "./Pods/*" \) | xargs SwiftGenStrings

Installation

Prebuilt Binaries

We tag releases and upload prebuilt binaries to GitHub. Checkout the releases tab or go straight to the latest release.

From Git

The project provides a Makefile. To export a binary run:

$ make release

The exported binary can be found under Products/SwiftGenStrings

CocoaPods

A podspec file for the project was released (see here). To consume the project, simply add the following to your Podfile:

pod 'SwiftGenStrings'

After running pod install or pod update, you will then find the binary under Pods/SwiftGenStrings/SwiftGenStrings

Testing

Xcode 9.2 seems to have a bug with running tests against macOS destination, luckily, xcodebuild works just fine:

$ make test

Requirements

  • Xcode 9.2
  • Swift 4.0.2

Limitations

  • SwiftGenStrings currently doesn't support multiple tables, only the default one - Localizable.strings.
  • It is not possible to use NSLocalizedString in string interpolation e.g.: let hello = "--- \(NSLocalizedString("Hello world!", comment: ""))" will not pickup the localized string.

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.