← All projects · Dev Tools
Strings Utility
Swift strings utility written in Go which automates boring Swift strings tasks like:
- Code on GitHub
Last updated May 2020
Overview
- Feature 1: Constantify Strings Creates global constant variables from all .swift files to a constant file
- Feature 2: Localize Strings Transform all valid translatable strings as NSLocalizedString and copies them to all
Localizable.stringsfiles while avoiding duplicated strings - Feature 3: Translate Strings Uses Google Cloud Translation to automatically translate all strings in all
Localizable.strings, allowing iOS, MacOS, etc apps to support multiple languages in a few seconds
Live Demo
Why Use?
- Avoid unintended typos
- Have strings autocompleted
- Easily manage all your strings in one file
- Auto generate strings
Localizable.stringsand avoid duplicate strings - Automatically translate all strings in
Localizable.strings
How to Use?
Download StringsUtility
- clone the repo
$ git clone https://github.com/SamuelFolledo/StringsUtility $ cd StringsUtility
Install Golang with Updated Homebrew:
- Make sure HomeBrew is updated
$ brew update $ brew install golang
Setup Google Cloud Translator: Required for feature 3 only
- Set up a Cloud Console project
- Download a private key as JSON
- While inside StringsUtility directory, run in terminal once
$ go get -u cloud.google.com/go/translate
-
Important: Run this command once each fresh terminal. Replace the
[PATH]to the path of the.jsonfile downloaded from setup 2 step 3. Instructions for more info or for Windows setupexport GOOGLE_APPLICATION_CREDENTIALS=[PATH]For example:
export GOOGLE_APPLICATION_CREDENTIALS=/Users/Samuel/Downloads/StringsUtility-Tester-785c7f11aedf.json
For further details, tips, recommendations go to Tips and Requirements
Run StringsUtility
-
run the program locally replacing
[PATH_TO_YOUR_PROJECT]with your project directory$ go build && go run main.go -dir=[PATH_TO_YOUR_PROJECT]For example:
go build && go run main.go -dir=/Users/macbookpro15/Desktop/StringsUtilityTesterTips and Requirements
-
Currently does not support multi line strings
-
To avoid unnecessary translation, strings which contains substrings like file extensions, keywords, and symbols will not be translated. Edit strings and files to follow these standards.
"/", "", "{", "}", "_", "#", "%", ".swift", ".xib", ".storyboard", ".jpg", ".jpeg", ".png", ".mp4", ".mp3", ".wav", ".mov", ".gif", "http", "https", ".com", "identifier" -
Strings like url, identifiers, and more which contains substrings like the following will not be constantify.
"/", "", "{", "}", "http", "https", ".com", "#", "%", "identifier"
For more tips and requirements click here
Links
-