All Projects → aloisdeniel → Flutter_sheet_localization

aloisdeniel / Flutter_sheet_localization

Licence: mit
Generate Flutter localization from a simple online Google Sheets.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to Flutter sheet localization

Goloc
A flexible tool for application localization using Google Sheets.
Stars: ✭ 42 (-80.19%)
Mutual labels:  csv, localization, internationalization
Easy localization
Easy and Fast internationalizing your Flutter Apps
Stars: ✭ 407 (+91.98%)
Mutual labels:  csv, localization, internationalization
Traduora
Ever® Traduora - Open-Source Translation Management Platform
Stars: ✭ 1,580 (+645.28%)
Mutual labels:  localization, internationalization
Phabricator zh hans
Phabricator zh-Hans Translation & Tools.
Stars: ✭ 113 (-46.7%)
Mutual labels:  localization, internationalization
Weblate
Web based localization tool with tight version control integration.
Stars: ✭ 2,719 (+1182.55%)
Mutual labels:  localization, internationalization
Android Gradle Localization Plugin
Gradle plugin for generating localized string resources
Stars: ✭ 100 (-52.83%)
Mutual labels:  csv, internationalization
Pseudo Localization
Dynamic pseudo-localization in the browser and nodejs
Stars: ✭ 109 (-48.58%)
Mutual labels:  localization, internationalization
Elasticsearch Dataformat
Excel/CSV/BulkJSON downloads on Elasticsearch.
Stars: ✭ 135 (-36.32%)
Mutual labels:  excel, csv
Dbwebapi
(Migrated from CodePlex) DbWebApi is a .Net library that implement an entirely generic Web API (RESTful) for HTTP clients to call database (Oracle & SQL Server) stored procedures or functions in a managed way out-of-the-box without any configuration or coding.
Stars: ✭ 84 (-60.38%)
Mutual labels:  excel, csv
Arbify
ARB files localization tool. Dedicated to Flutter and its intl package.
Stars: ✭ 168 (-20.75%)
Mutual labels:  localization, internationalization
Weihanli.npoi
NPOI Extensions, excel/csv importer/exporter for IEnumerable<T>/DataTable, fluentapi(great flexibility)/attribute configuration
Stars: ✭ 157 (-25.94%)
Mutual labels:  excel, csv
Formatjs
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Stars: ✭ 12,869 (+5970.28%)
Mutual labels:  localization, internationalization
Combine Csv Files In The Folder
Tiny script to automate everyday task
Stars: ✭ 91 (-57.08%)
Mutual labels:  excel, csv
Filecontextcore
FileContextCore is a "Database"-Provider for Entity Framework Core and adds the ability to store information in files instead of being limited to databases.
Stars: ✭ 91 (-57.08%)
Mutual labels:  excel, csv
Django Translations
Django model translation for perfectionists with deadlines.
Stars: ✭ 109 (-48.58%)
Mutual labels:  localization, internationalization
Tabtoy
高性能表格数据导出器
Stars: ✭ 1,302 (+514.15%)
Mutual labels:  excel, csv
Dom I18n
Provides a very basic HTML multilingual support using JavaScript
Stars: ✭ 125 (-41.04%)
Mutual labels:  localization, internationalization
React Translated
A dead simple way to add complex translations (i18n) in a React (DOM/Native) project 🌎🌍🌏
Stars: ✭ 176 (-16.98%)
Mutual labels:  localization, internationalization
Gatsby Starter Prismic I18n
Based on gatsby-starter-prismic with Internationalization (i18n) support
Stars: ✭ 77 (-63.68%)
Mutual labels:  localization, internationalization
Keys Translations Manager
KTM, a locale management web app built on MERN stack, lets you manage and control locales in one place. It's particularly useful for someone who needs to manage multiple internationalization/localization projects.
Stars: ✭ 81 (-61.79%)
Mutual labels:  localization, internationalization

Flutter Google Sheet localizations generator

Generates a localizations delegate from an online Google Sheet file.

Install

Add the following to your pubspec.yaml:

dependencies:
  flutter_sheet_localization: <latest>
  intl: <latest>

dev_dependencies:
  flutter_sheet_localization_generator: <latest>
  build_runner: ^1.10.2

Usage

1. Create a Google Sheet

Create a sheet with your translations (following the bellow format, an example sheet is available here) :

example

Make sure that your sheet is shared :

share

Extract from the link the DOCID and SHEETID values : https://docs.google.com/spreadsheets/d/<DOCID>/edit#gid=<SHEETID>) :

2. Declare a localization delegate

Declare the following AppLocalizationsDelegate class with the SheetLocalization annotation pointing to your sheet in a lib/localization.dart file :

import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_sheet_localization/flutter_sheet_localization.dart';

part 'localization.g.dart';

@SheetLocalization("DOCID", "SHEETID", 1) // <- See 1. to get DOCID and SHEETID
// the `1` is the generated version. You must increment it each time you want to regenerate
// a new version of the labels.
class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
  const AppLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) =>
      AppLocalizations.languages.containsKey(locale);
  @override
  Future<AppLocalizations> load(Locale locale) =>
      SynchronousFuture<AppLocalizations>(AppLocalizations(locale));
  @override
  bool shouldReload(AppLocalizationsDelegate old) => false;
}

3. Generate your localizations

Run the following command to generate a lib/localization.g.dart file :

flutter packages pub run build_runner build

4. Configure your app

Update your Flutter app with your newly created delegate :

MaterialApp(
    locale: AppLocalizations.languages.keys.first, // <- Current locale
    localizationsDelegates: [
    const AppLocalizationsDelegate(), // <- Your custom delegate
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    ],
    supportedLocales:
        AppLocalizations.languages.keys.toList(), // <- Supported locales
    // ...
);

5. Display your labels

final labels = AppLocalizations.of(context);
print(labels.dates.month.february);
print(labels.templated.hello(firstName: "World"));
print(labels.templated.contact(Gender.male, lastName: "John"));

Regeneration

Because of the caching system of the build_runner, it can't detect if there is a change on the distant sheet and it can't know if a new generation is needed.

The version parameter of the @SheetLocalization annotation solves this issue.

Each time you want to trigger a new generation, simply increment that version number and call the build runner again.

Google Sheet format

You can see an example sheet here.

Global format

The file should have :

  • A first header row
    • Column 0 : "Key"
    • then each supported language code ("en", "fr", ...)
  • Following rows for labels
    • Column 0 : the label key (can be a hierarchy, separated by dots)
    • then each translation based on language code of the column

Ignoring a column

Sometimes you may need to add comments for translators. For this, simply add a column with a name between parenthesis and the column will be completely ignored by the generator.

Example :

Key (Comments) fr en
example.man(Gender.male) This is a man title on home page homme man
example.man(Gender.female) This is a woman title on home page femme woman

Conditionals

It is pretty common to have variants of a label based on a condition (for example: Genders, Plurals, ...).

Simply duplicate your entries and end them with (<ConditionName>.<ConditionCase).

Example :

Key fr en
example.man(Gender.male) homme man
example.man(Gender.female) femme woman

See example for more details.

Plurals

The conditionals can be used the same way for plurals :

Example :

Key fr en
example.man(Plural.zero) hommes man
example.man(Plural.one) homme man
example.man(Plural.multiple) hommes men

From your Dart code, you can then define an extension :

extension PluralExtension on int {
  Plural plural() {
    if (this == 0) return Plural.zero;
    if (this == 1) return Plural.one;
    return Plural.multiple;
  }
}

See example for more details.

Dynamic labels

You can insert a {{KEY}} template into a translation value to have dynamic labels.

A Dart function will be generated to be used from your code.

/// Sheet
values.hello, "Hello {{first_name}}!"

/// Code
print(labels.values.hello(firstName: "World"));

Typed parameters

You can also add one of the compatible types (int, double, num, DateTime) to the parameter by suffixing its key with :<type>.

/// Sheet
values.price, "The price is {{price:double}}\$"

/// Code
print(labels.values.price(price: 10.5));

Formatted parameters

You can indicate how the templated value must be formatted by ending the value with a formatting rule in brackets [<rule-key>]. This can be particulary useful for typed parameters.

The available formatting rules depend on the type and generally rely on the intl package.

Type rule-key Generated code
double, int, num decimalPercentPattern, currency, simpleCurrency, compact, compactLong, compactSimpleCurrency, compactCurrency, decimalPattern, percentPattern, scientificPattern NumberFormat.<rule-key>(...)
DateTime Any date format valid pattern DateFormat('<rule-key>', ...).format(...)

Examples:

/// Sheet
values.price, "Price : {{price:double[compactCurrency]}}"

/// Code
print(labels.values.price(price: 2.00));
/// Sheet
values.today, "Today : {{date:DateTime[EEE, M/d/y]}}"

/// Code
print(labels.values.today(date: DateTime.now()));

Why ?

I find the Flutter internationalization tools not really easy to use, and I wanted a simple tool for sharing translations. Most solutions also use string based keys, and I wanted to generate pure dart code to improve permormance.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].