Git Product home page Git Product logo

gsheet_to_arb's Introduction

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}

gsheet_to_arb's People

Contributors

gocal avatar isakdl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gsheet_to_arb's Issues

Creating config file does not work

When running the command

pub run gsheet_to_arb:import --create-config gsheet_to_arb.yaml

I get the following error:

Unhandled exception:
FormatException: Could not find an option named "create-config".
#0      Parser.validate (package:args/src/parser.dart:261:21)
#1      Parser.parseLongOption (package:args/src/parser.dart:250:7)
#2      Parser.parse (package:args/src/parser.dart:90:11)
#3      ArgParser.parse (package:args/src/arg_parser.dart:320:45)
#4      main (file:///Users/isak/.pub-cache/hosted/pub.dartlang.org/gsheet_to_arb-0.0.6/bin/import.dart:24:10)
<asynchronous suspension>
#5      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:298:32)
#6      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:171:12)
pub failed (255)

Could solve the issue by creating the config manually from the template file.

Importing existing arb files

Hi, I have an app that uses typical Flutter localization workflow with arb files, intl_translation and .dart files. Is there a way to import this translation data to the template Google sheet?

NullSafety

Not sure if this will be a priority issue but a lot of packages already migrated to support null safety.

Explain why this exists

flutter_sheet_localization seems to do what gsheet_to_arb does in a simpler manner. I realize that this project was created earlier.

It would be useful to know the advantages this package has.

Update petitparser version

hi, thank you for this useful tool :-)

In pubspec.yaml, petitparser dependency is set to this : ">=1.1.3 <3.0.0"
Version 3 is excluded so the last petitparser compatible version is 2.4.0 from June 2019.
petitparser projet has released several versions in 2020 (3.0.0 to 3.0.4) and some packages (flutter_svg) require version >3.0.0.
Could you update this dependency ?

sheetId doesn't work

gsheet_to_arb imports the first sheet no matter what sheetId is specified in config file

Using without authentication

Hi Marcin,

It refers to Issue #23 in some way.
We can provide google sheet via url without any authentication. It is read-only of course.
Is it possible to use this package without authentication?

Anyway: Good job ;)

Pozdro!

How to use this.Maybe some issue.

/// number of songs plural
String numberOfSongsAvailable(int count) => Intl.plural(count,
zero: 'No songs found.',
one: 'One song found.',
two: '$count songs found.',
few: '$count songs found.',
other: '$count song found.',
many: '$count songs found.',
name: 'numberOfSongsAvailable',
args: [count],
desc: 'number of songs plural');

/// currency dolars
String amountDollars(int count) => Intl.plural(count,
one: '$count Canadian dollar',
other: '$count Canadian dollars',
name: 'amountDollars',
args: [count],
desc: 'currency dolars');

Not compatible with latest intl_translation version

Because every version of gsheet_to_arb depends on analyzer ^0.33.0-alpha.0 and intl_translation 0.17.5 depends on analyzer ^0.36.0, gsheet_to_arb is incompatible with intl_translation 0.17.5.
And because no versions of intl_translation match >0.17.5 <0.18.0, gsheet_to_arb is incompatible with intl_translation ^0.17.5.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.