mirrorrim
v1.2.1
Published
Tool for generating localization files for iOS and Android
Downloads
20
Maintainers
Readme
mirrorrim
This is a node app for generating iOS/Android localization files from local CSV or Google Sheet. You can consider this as a solution for maintainning multiple languages in iOS/Android platform btween developers and whoever updates the wordings.
Install
Local(recommended): yarn add mirrorrim --dev
Global: yarn global add mirrorrim
or npm install mirrorrim --global
Usage
Manually
mirrorrim --output-dir './outputs' --input-path './resources/test.csv'
Quick Test or Wordings are not sensitive
Make sure you have your Google Sheet file shared as public read-only so mirrorrim can pull from Google.
mirrorrim --output-dir './outputs' --googleFileId 1Ik0mRByqVFldbAjDvrwGFx_CrM6-fsEKN0IzZnAr7rI
or add a mirrorrim
section in your package.json and run mirrorrim
at your root folder
"mirrorrim": {
"googleFileId": "1Ik0mRByqVFldbAjDvrwGFx_CrM6-fsEKN0IzZnAr7rI",
"outputDir": "./PATH_TO_YOUR_DEST",
"platforms": ["ios", "android"]
},
Configured(recommended)
add a mirrorrim
section in your package.json and run yarn mirrorrim
at your root folder
"mirrorrim": {
"googleCredential": "./google-credential.json",
"googleFileId": "1Ik0mRByqVFldbAjDvrwGFx_CrM6-fsEKN0IzZnAr7rI",
"outputDir": "./PATH_TO_YOUR_DEST",
"platforms": ["ios", "android"]
},
The output looks like
If you see a 404 error, follow the setup here.
List of options:
--output-dir <string> | default: ./output
--platforms <string> | default: ['ios', 'android']
--input-path <file> | path to local csv
--google-file-id <string> | google file id, should be sheet file
--google-credential <file> | path to google credentials.json
The tool currently onlys supports en and zh-Hans. Will support more in later phase. Please make sure you have the same column title as below for the sheet.
Example
Let's say your wordings are kept at https://docs.google.com/spreadsheets/d/1Ik0mRByqVFldbAjDvrwGFx_CrM6-fsEKN0IzZnAr7rI/edit?usp=sharing
Follow the setup here to get the google-credential.json
file
iOS
Before you run this script, make sure you already have the Localizable
file created and corresponding language enabled, otherwise you'll have to switch around manually.
After install at your project root folder, add following section to your package.json
"mirrorrim": {
"googleCredential": "./google-credential.json",
"googleFileId": "1Ik0mRByqVFldbAjDvrwGFx_CrM6-fsEKN0IzZnAr7rI",
"outputDir": "./PATH_TO_YOUR_DEST",
"platforms": ["ios"]
},
And run mirrorrim
at your project root folder. You can add the localization files from Xcode now.
What's More For iOS?
You can combine it with R.swift, then use R.string.localizable.alert_ok()
for localized string.
Wait... R.swift currently doesn't support in-app language switch well, but with this extension https://gist.github.com/jhonny-me/dd2edb43fb167d1f55f79021718507b7
you can do: R.string.localizable.alert_ok.localized()
What about params? I got you covered: R.string.localizable.count_number.localized().withInputs(2, 'piggets')
When you want to change language simply call StringResource.language = "zh-Hans"
Android
After install at your project root folder, add following section to your package.json
"mirrorrim": {
"googleCredential": "./google-credential.json",
"googleFileId": "1Ik0mRByqVFldbAjDvrwGFx_CrM6-fsEKN0IzZnAr7rI",
"outputDir": "./PATH_TO_YOUR_DEST",
"platforms": ["android"]
},
And run mirrorrim
at your project root folder. You can add the localization files from your IDE now.
How to setup Google Account
create project and enable drive api
- Go to the Google Developers Console
- Select your project or create a new one (and then select it)
- Enable the Drive API for your project
- In the sidebar on the left, select APIs & Services > Library
- Search for "drive"
- Click on "Google Drive API"
- click the blue "Enable" button
create service account and download the json credential
- In the sidebar on the left, select APIs & Services > Credentials
- Click blue "+ CREATE CREDENTIALS" and select "Service account" option
- Enter name, description, click "CREATE"
- You can skip permissions, click "CONTINUE"
- Click "+ CREATE KEY" button
- Select the "JSON" key type option
- Click "Create" button
- your JSON key file is generated and downloaded to your machine (it is the only copy!)
- click "DONE"
- rename the downloaded json to
google-credential.json
- add the generated bot user to your Google Sheet as a viewer, it can be found at the
client_email
at the downloaded json.
Be careful - never check your API keys / secrets into version control (git)