gsheet_to_arb 0.1.2 gsheet_to_arb: ^0.1.2 copied to clipboard
Imports Application Resource Bundle (ARB) from Google Sheets documents
Import translations from Google spreadsheet #
This plugin allows you to:
- Imports Application Resource Bundle (ARB) from Google Sheets
- automatically create dart source code
- supports placeholders and plurals
- groups translations by categories (context)
Usage #
Import Translation files from the Google Sheet #
-
Setup plugin configuration yaml file (you only need to do it once.)
-
Import ARB and Dart source files from the Google Sheet
pub run gsheet_to_arb:import
or for flutter
flutter pub run gsheet_to_arb:import
Setup #
1. Create translation spreadsheet based on the template #
-
Copy the template to your Drive account -
File -> Make a copy
-
Save
DOCUMENT_ID
of your spreadsheet https://docs.google.com/spreadsheets/d/DOCUMENT_ID/edit#gid=0 -
For more details about spreasheet structure see Spreadsheet format section
2. Create Google Sheets API credentials either by using Client or Server authentication. #
3. Configure your Dart project #
-
Add gsheet_to_arb dev dependency to the pubspec.yaml
dev_dependencies: gsheet_to_arb: ^0.1.2
-
Updated dependencies
pub update
-
Create plugin configuration
pub run gsheet_to_arb:import --create-config
- It will add plugin configuration to the
pubspec.yaml
file and creategsheet_to_arb.yaml
authentication file for the gsheet credentials
-
Update plugin configuration created in
pubspec.yaml
e.g.gsheet_to_arb: arb_file_prefix: 'intl' # suffix of the create arb files e.g. intl_en.arb localization_file_name: 'l10n' # Genrated intl dart file name e.g. L10n.dart output_directory: 'lib/l10n' # where all the dart and arb data are sotre add_context_prefix: false # should add category prefix to the keys e.g. common_title et.c gsheet: auth_file: './gsheet_to_arb.yaml' # file with the gsheet authentication configuration category_prefix: "# " document_id: 'TODO' sheet_id: '0'
-
Update gsheet authentication configuration created in
gsheet_to_arb.yaml
- either add client
oauth_client_id: client_id: "TODO" client_secret: "TODO"
- or server credentials
service_account_key: client_id: "TODO" client_email: "TODO" private_key: "TODO"
Spreadshseet format #
Rows #
- the first row is reserved for the header section and contains label of the related columns
- other rows
- if rows start with the
category_prefix
value (#
default) the all the following rows will use the category as a context (see: ARB context, andadd_context_prefix
parameter) - empty rows are ignored
- if rows start with the
Columns #
- the first column contains eiter key name or category prefix
- the second column contains item description
- all the following column contains traslation files
- make sure spreadsheet contains only valid colums - i.e. with langauge key value
Values #
-
Placeholder
- simply add
{placeholder_name}
to the translation
- simply add
-
Plurals
- plurals are identified by the key metadata - if key ends with one of the following
- zero, one, two, few, many, other - it's considered as a plural
- plural use special placeholder
{count}
to mark value provied as a translation parameter
- plurals are identified by the key metadata - if key ends with one of the following