flutter_translation_sheet 1.0.5+11 flutter_translation_sheet: ^1.0.5+11 copied to clipboard
Flutter Translation Sheet Generator is a super simple tool to help you deal with localization (l10n), using automatic GoogleSheet translations (via Google Translate) and the generation of json and dart files.
Flutter Translation Sheet Generator [fts] #
Command line application to make your l10n super fast. Compose your strings in yaml/json format and use GoogleSheet for auto translate.
🧰 Install: #
You need to have
flutter
ordart
SDK in your System PATH.
flutter pub global activate flutter_translation_sheet
Now just run fts
in any folder to create a template configuration file.
⚙️ Usage: #
Go with your terminal in any folder (or Flutter project folder), and run fts run
.
First time will create a template for you, and you will have to get your Google credentials json.
Once you get the json, go to tfconfig.yaml
and in the gsheet:
there are two ways to fill the credentials (you only need to use one):
- Add
credentials_path:
followed by the path of your json. You can copy the json file to the root folder of your project. The path can be absolute or relative.
Example:
gsheets:
credentials_path: c:/my_project/credentials.json or ./credentials.json
⚠️ NOTE TO WINDOWS USERS: paths should be either in the form "C:\\Users\\etc", with two backslash characters, or using forwardslash characters instead such as "C:/Users/etc".
- Add
credentials:
followed by the whole credentials json content
Example:
gsheets:
credentials: {
"type": "service_account",
"project_id": "project-id",
"private_key_id": "",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCB-----END PRIVATE KEY-----\n",
"client_email": "gsheets@project.iam.gserviceaccount.com",
"client_id": "123456",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gsheets%40evolution-cp-calculator.iam.gserviceaccount.com"
}
You can find more information in the comments in tfconfig.yaml
and fill the gsheet:
section, and change the output folder as needed.
Once you have your configuration file ready, run fts
to generate your sample google sheets.
Take the sample data input as reference, and use it in your own project.
fts will try to keep the local input and the remote sheet in sync, and automatically generate the locales for you every time you run it.
After a while of not using it, Google Sheet performance slow down on every request, so it might take a little longer to get the output generated. Once it warms up (run 1 time) the sync performance is pretty solid.
fts fetch
Unlike fts run
, fetch
doesn't sync, nor validates the data structure.
Uses the local strings as entry map, downloads the latest data from GoogleSheet and generates the files accordingly. Is a much faster process. Very useful when you made manual corrections in your sheets for the auto-translated locales.
Do not manually modify the master language column on your Google Sheet, change the data in the string source file
and let fts
do the upload.
If there are differences of master lang strings between local and remote, the entire row will be cleared and regenerated with auto translation using the latest strings, and manual changes will get lost.
Currently you have to be careful, and keep your manual translations backed up just in case you modify the master language string.
Variables: #
To store "variables" or placeholders in your strings to be replaced later in your code, use the follow notation:
"Welcome back {{user}}, today is {{date}}."
It will store the values in the sheet as {{0}} {{1}} and so on, to avoid complications with GoogleTranslate, and it will generate a vars.lock file in the directory where you point your "entry_file" in config.
param_output_pattern: "{{*}}"
📝 Considerations: #
-
In your spreadsheet, the first column will always be your "keys", don't change that, don't move the column.
-
In your
trconfig.yaml
, the first locale you define is your master language:
locales:
- es ## master language used in `entry_file`
- en ## language list to translate.
- ko
-
The tool only analyzes the locales in your config... will not keep updated any other sheet column with other locales.
-
You can move the columns, or add new columns, around as long as the
keys
is always the first (A1). -
The 1st ROW in your sheet are the "headers", don't change the autogenerated names.
-
If fts finds the 2nd ROW empty in any column, it will take the data corrupted, and will re-upload for translation.
-
If the row count from keys is different from the master language, it will invalidate the entire sheet.
Thanks for passing by!