MacMeDan / Localizer

Tool to help with managing Localized strings in a way that gives ease of use, safety and autocompletion.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Localizer

Purpose:

To make Localization simple, automatic, and pain free.

Usage

Recommended:

  1. Generate the executable script
  2. Add Script to base of your project
  3. Run script on build

Alternative:

Run the project and use the CLI ( Command Line interface ) to interact with the program.

Executable Script

To generate a executable script you have to combine all necessary pieces of this project into a single executable. By default the executable automatically executes a modified version of option 6 Find Strings in file of the command line tool but instead of prompting for the path it takes the path to a folder as a parameter. It will then look for any file within that folder that is of type .swift and scan it for unlocalized strings.

You can modify the scripts as you please to suite your own needs and regenerate the executable script.

To create an executable you will need to combine all dependencies including extensions. To create the Localizer executable that is found in this project you just need to navigate thought terminal to this project on your computer. Then run: swiftc Localizer/ScriptFiles* -o LocalizerScript

This creates an executable named LocalizerScript. To use this script you preface it with ./ then the script LocalizerScript add a space to seperate the script from the parameter then add the parameter which is a path to a folder in your project. ./LocalizerScript "/path/to/folder/you/would/like/scanned/and/converted"

Then watch the magic happen. WARNING: Make sure to review all changes that have been made to your project and that they are correct. Open a new issue and submit a fix if there is a way to improve the project.

Generated Resources usage

Inside the main project you can access localized strings like this R.{stringInCammelCased}

EX: self.title = R.awesomeViewController this will return a localized version of "Awesome View Controller"

Command Line Tool usage

Specify the source file Specify the destination file Specify the destination for the generated ResourceFile.swift

Displayed options

Please select an option:

  1. Add new entry with auto generated key
  2. Add new entry with specified key
  3. Generate Resources
  4. Generate Strings
  5. Generate Strings Sorted by Value not Key
  6. Find Strings in file

1 Add new entry with auto generated key

auto generates a key based off of the string you entered by camelCased the phrase and removing spaces. Adds that entry to the Localizable.strings file.

2 Add new entry with specified key

lets you specify a key and value Adds that entry to the Localizable.strings file.

3 Generate Resources

Creates the Resources.swift based off of the contents of the Localizable.strings file

4 Generate Strings

Takes the source file specified and generates a new Localizable.strings

  1. by parsing the values for each entry.
  2. Auto generating a camelCased key
  3. Adding a comment and the [key: value] to theLocalizable.strings file.

5 Generate Strings Sorted by Value not Key

This option takes your Localizable.Strings file and sorts it by the Value of the entry

6 Find Strings in file

  1. Asks for the path to a file
  2. Parses the file for any Strings wrapped in the " Character
  3. Generates and sorts alphabetically an entry into the Localizable.strings file
  4. Generates an Entry into the Resources.swift enum
  5. Replaces the String with a reference to the Resource IE R.newGeneratedKey so you don’t have to.

Useful resources:

Scripting in Swift is Pretty Awesome mokacoding Awesome XCode Scripts Continuous Integration: Scripting Xcode Builds Shell Script Basics Secret variables in Xcode AND your CI for fun and profit 💌 Swift Scripting Redux: Localization How to Pass Arguments to a Bash-Script Swift Scripting Part 1: Command Line Arguments and Using Foundation

About

Tool to help with managing Localized strings in a way that gives ease of use, safety and autocompletion.


Languages

Language:Swift 100.0%