पैकेज, रिपॉज़िटरी और ऐप श्रेणियाँ खोजें

पैकेज विवरणv5.1.7

flutter_sheet_localization_generator

Google शीट फ़ाइल्स से Flutter स्थानीयकरण कोड जनरेटर।

30-दिन डाउनलोड
76
लाइक
22
Pub अंक
130

पैकेज इंस्टॉल करें

flutter pub add flutter_sheet_localization_generator

पैकेज अवलोकन

सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।

एक फ्लटर पैकेज जो गूगल शीट से स्थानीयीकरण फ़ाइलें बनाता है, जिससे फ्लटर ऐप्स के लिए बिना किसी दिक्कत के अंतर्राष्ट्रीयकरण संभव होता है। यह एक साझा गूगल शीट में संग्रहीत अनुवादों को डार्ट स्थानीयीकरण फ़ाइलों में सिंक करने की प्रक्रिया को स्वचालित करता है, जिससे हाथ से काम कम होता है और त्रुटियों का जोखिम कम होता है। जनरेटर कई भाषाओं का समर्थन करता है और एक सरल कमांड-लाइन इंटरफ़ेस के माध्यम से फ्लटर विकास कार्यप्रवाह में सीधे एकीकृत होता है। बहुभाषी सामग्री पर काम करने वाली टीमों के लिए आदर्श है जिन्हें स्थानीयीकरण सेटअप के बारे में गहन तकनीकी ज्ञान की आवश्यकता नहीं होती है।

उपयोग

  • साझा Google शीट्स से स्थानीयकरण फ़ाइलें उत्पन्न करना
  • Flutter ऐप में अनुवाद अद्यतन को स्वचालित करना
  • सहयोगात्मक अनुवाद कार्यप्रणाली
  • संस्करणों के बीच स्थिर भाषा स्ट्रिंग बनाए रखना
  • गैर-तकनीकी टीम सदस्यों को अनुवाद प्रबंधित करने की अनुमति देना

मुख्य विशेषताएँ

  • Google शीट्स से डार्ट स्थानीयकरण फ़ाइलें उत्पन्न करता है
  • कई भाषाओं का समर्थन करता है
  • Flutter के साथ कमांड-लाइन एकीकरण
  • बादल-आधारित अनुवाद स्रोत के साथ वास्तविक समय सिंक
  • आवश्यक न्यूनतम कॉन्फ़िगरेशन

इनके लिए उपयुक्त

  • बहुभाषी Flutter ऐप्स का प्रबंधन करने वाली टीमें
  • सहयोगात्मक अनुवाद उपकरणों का उपयोग करने वाले विकासकर्ता
  • अक्सर स्थानीयकरण अपडेट वाले प्रोजेक्ट
  • विकासकर्मियों के साथ काम करने वाले गैर-तकनीकी अनुवादक
  • स्केलेबल अंतरराष्ट्रीयकरण की आवश्यकता वाले ऐप्स

विचार योग्य बातें

  • उचित अनुमतियों के साथ Google शीट के एक्सेस की आवश्यकता है
  • शीट फ़ैच करने के लिए इंटरनेट कनेक्टिविटी पर निर्भर करता है
  • प्रारंभिक सेटअप में Google Cloud के साथ प्रमाणीकरण की आवश्यकता होती है
  • ऑफलाइन केवल अनुवाद कार्य प्रवाह के लिए उपयुक्त नहीं है
  • स्रोत के रूप में Google Sheets पर सीमित (अन्य प्लेटफॉर्म नहीं)

मूल README

संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।

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>
  flutter_localizations:
    sdk: flutter

dev_dependencies:
  flutter_sheet_localization_generator: <latest>
  build_runner: <latest>
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<AppLocalizationsData> {
  const AppLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) => localizedLabels.containsKey(locale);

  @override
  Future<AppLocalizationsData> load(Locale locale) =>
      SynchronousFuture<AppLocalizationsData>(localizedLabels[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.

श्रेणियाँ

निर्भरताएँ

निर्भरता सूची 13 आइटम

सोर्स रिपॉज़िटरी

इस पैकेज का उपयोग करने वाले प्रोजेक्ट

अभी कोई डेटा उपलब्ध नहीं है।