To make Localization simple, automatic, and pain free.
- Generate the executable script
- Add Script to base of your project
- Run script on build
Run the project and use the CLI ( Command Line interface ) to interact with the program.
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.
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"
Specify the source file Specify the destination file Specify the destination for the generated ResourceFile.swift
- Add new entry with auto generated key
- Add new entry with specified key
- Generate Resources
- Generate Strings
- Generate Strings Sorted by Value not Key
- Find Strings in file
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.
lets you specify a key and value
Adds that entry to the Localizable.strings
file.
Creates the Resources.swift
based off of the contents of the Localizable.strings
file
Takes the source file specified and generates a new Localizable.strings
- by parsing the values for each entry.
- Auto generating a
camelCased
key - Adding a comment and the [key: value] to the
Localizable.strings
file.
This option takes your Localizable.Strings file and sorts it by the Value
of the entry
- Asks for the path to a file
- Parses the file for any Strings wrapped in the
"
Character - Generates and sorts alphabetically an entry into the
Localizable.strings
file - Generates an Entry into the
Resources.swift
enum
- Replaces the
String
with a reference to the Resource IER.newGeneratedKey
so you don’t have to.
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