gsheet_to_arb 0.1.8

  • Readme
  • Changelog
  • Example
  • Installing
  • 64

Import translations from Google Sheets #

pub package

  • Import Application Resource Bundle (ARB) from Google Sheets
  • automatically create Dart intl classes
  • group translations by categories (context)
  • supports placeholders and plurals

Usage #

Import Translation files from the Google Sheet #

  1. Setup plugin configuration yaml file (you only need to do it once.)

  2. 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 #

2. Create Google Sheets API credentials either by using Client or Server authentication. #

3. Configure your Dart project #

  1. Add gsheet_to_arb dev dependency to the pubspec.yaml

     dev_dependencies:
       gsheet_to_arb: ^0.1.8
    
  2. Updated dependencies pub update

  3. Create plugin configuration

     pub run gsheet_to_arb:import --create-config
    
  • It will add plugin configuration to the pubspec.yaml file and create gsheet_to_arb.yaml authentication file for the gsheet credentials
  1. Update plugin configuration created in pubspec.yaml e.g.

     gsheet_to_arb: 
         arb_file_prefix: 'intl' # suffix of the created 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 stored
         add_context_prefix: false # should add category prefix to the keys e.g. common_app_title
         gsheet: 
             auth_file: './gsheet_to_arb.yaml' # file with the gsheet authentication configuration
             category_prefix: "# " 
             document_id: 'TODO'
             sheet_id: '0'
             columns: # This is an optional setting, if unused will fallback to default values
                 key: 0 # The column where the key for the translation is, defaults to 0
                 description: 1 # The column where the description is, defaults to 1
                 first_language_key: 2 # The first column for the language copy, assumes that all other columns after this one also contains a language translation, defaults to 2
             rows: # This is an optional setting, if unused will fallback to default values
                 header_row: 0 # The header row containing the title for each column, such as language codes, defaults to 0
                 first_translation_row: 1 # The first row containing transaltions that should be parsed, assumes that all rows after this one also should be parsed, defaults 1
    
  2. 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"
    

Spreadsheet 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) all the following rows will use the category as a context (see: ARB context, and add_context_prefix parameter)
    • empty rows are ignored
    • rows with an empty key column are ignored

Columns #

  • the first column key contains either key name or category prefix
  • the second column description contains item description
  • all the following column (language codes e.g. en, pl etc.) contains traslation files
  • will start parsing from the first language column and stop parsing on the last column or the first empty column, which ever comes first

Values #

  • Placeholder

    • simply add {placeholder_name} to the translation
  • 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

TODO #

  • support placeholder parameter types (e.g. int, date, text, double) - {items, int}

0.1.8 #

  • Add ability to configure Sheet columns and rows (@Isakdl)
  • Update pubspec dependencies (@jarekb123)

0.1.7 #

  • Readme fix

0.1.4 #

  • Fix problem with plurals generation

0.1.3 #

  • Documentation update

0.1.2 #

  • Add logging output

0.1.1 #

  • Add plurals
  • Fix create-config flag
  • Change configuration structure - moved to pubspec.yaml

0.0.7 #

  • Update dependencies

0.0.6 #

  • Category prefix configuration

0.0.5 #

  • Support placeholders in ARB resources

0.0.4 #

  • Server-side (private key) authentication

0.0.3 #

  • Generate dart class from arb file

0.0.2 #

  • Import ARB from Google Sheets

0.0.1 #

  • Initial version

example/lib/main.dart

import 'package:intl/intl.dart';

import 'l10n/_messages_all.dart';
import 'l10n/l10n.dart';

void main() async {
  print('MAIN');

  Intl.defaultLocale = 'pl';
  await initializeMessages(Intl.defaultLocale);

  final l10n = L10n();

  print(l10n.title);
  print(l10n.login);
  print(l10n.singleArgument('arg'));
  print(l10n.twoArguments('arg1', 'arg2'));

  // plurals
  print(l10n.numberOfSongsAvailable(0));
  print(l10n.numberOfSongsAvailable(1));
  print(l10n.numberOfSongsAvailable(2));
  print(l10n.numberOfSongsAvailable(5));
  print(l10n.numberOfSongsAvailable(10));

  
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  gsheet_to_arb: ^0.1.8

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:gsheet_to_arb/gsheet_to_arb.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
41
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Jul 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:gsheet_to_arb/gsheet_to_arb.dartpackage:gsheet_to_arb/src/config/plugin_config_manager.dartpackage:gsheet_to_arb/src/utils/yaml_utils.dartdart:io

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:gsheet_to_arb/gsheet_to_arb.dartpackage:gsheet_to_arb/src/config/plugin_config_manager.dartpackage:gsheet_to_arb/src/utils/yaml_utils.dartdart:io

Health suggestions

Format lib/src/config/plugin_config.dart.

Run dartfmt to format lib/src/config/plugin_config.dart.

Format lib/src/config/plugin_config_manager.dart.

Run dartfmt to format lib/src/config/plugin_config_manager.dart.

Format lib/src/gsheet/ghseet_importer.dart.

Run dartfmt to format lib/src/gsheet/ghseet_importer.dart.

Format lib/src/parser/translation_parser.dart.

Run dartfmt to format lib/src/parser/translation_parser.dart.

Maintenance issues and suggestions

Support latest dependencies. (-30 points)

The version constraint in pubspec.yaml does not support the latest published versions for 3 dependencies (code_builder, googleapis, petitparser).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
args >=1.5.2 <2.0.0 1.6.0
code_builder >=3.1.3 <3.3.0 3.2.1 3.3.0
dart_style >=1.3.3 <2.0.0 1.3.6
file_utils >=0.1.1 <0.2.0 0.1.4
googleapis ^0.54.0 0.54.0 0.55.0
googleapis_auth ^0.2.6 0.2.12
intl >=0.16.1 <0.17.0 0.16.1
intl_translation >=0.17.9 <0.18.0 0.17.9 0.17.10
json_annotation >=3.0.1 <3.1.0 3.0.1
logging >=0.11.3+2 <0.12.0 0.11.4
path >=1.6.4 <2.0.0 1.7.0
petitparser >=1.1.3 <3.0.0 2.4.0 3.0.4
quiver >=2.0.5 <2.2.0 2.1.3
recase >=3.0.0 <3.1.0 3.0.0
yaml >=2.2.0 <2.3.0 2.2.1
Transitive dependencies
_discoveryapis_commons 0.1.9 0.2.0
_fe_analyzer_shared 5.0.0
async 2.4.2
built_collection 4.3.2
built_value 7.1.0
charcode 1.1.3
collection 1.14.13
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
fixnum 0.10.11
glob 1.2.0
globbing 0.3.1
html 0.14.0+3
http 0.12.1
http_parser 3.1.4
js 0.6.2
matcher 0.12.8
meta 1.2.1
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
pub_semver 1.4.4
source_span 1.7.0
stack_trace 1.9.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0
watcher 0.9.7+15
Dev dependencies
analyzer >=0.39.0 <0.40.0 0.39.12
build_runner ^1.0.0
json_serializable ^3.2.5
pedantic ^1.9.0 1.9.1
test ^1.5.3