패키지, 저장소 및 앱 카테고리 검색

패키지 상세v5.1.7

flutter_sheet_localization_generator

Google 시트 파일에서 Flutter 로컬라이제이션 코드를 생성하는 도구입니다.

30일 다운로드
76
좋아요
22
Pub 점수
130

패키지 설치

flutter pub add flutter_sheet_localization_generator

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Google 시트에서 로컬라이제이션 파일을 생성하는 플러터 패키지로, 플러터 앱에 원활한 국제화를 가능하게 합니다. 공유된 Google 시트에 저장된 번역을 Dart 로컬라이제이션 파일과 자동으로 동기화하여 수작업을 줄이고 오류를 최소화합니다. 이 생성기는 여러 언어를 지원하며 간단한 명령줄 인터페이스를 통해 플러터 개발 워크플로우에 직접 통합됩니다. 로컬라이제이션 설정에 대한 깊은 기술 지식이 필요 없는 팀이 다국어 콘텐츠를 협업할 때 이상적입니다.

사용 사례

  • 공유된 Google 시트에서 로컬라이제이션 파일 생성
  • Flutter 앱에서 번역 업데이트 자동화
  • 협업 번역 워크플로우
  • 버전 간에 일관된 언어 문자열 유지하기
  • 비기술 팀원들이 번역을 관리할 수 있도록 하기

주요 기능

  • Google 시트에서 Dart 로컬라이제이션 파일 생성
  • 다중 언어를 지원합니다
  • Flutter와의 명령줄 통합
  • 클라우드 기반 번역 소스와 실시간 동기화
  • 필수 최소 구성

적합한 대상

  • 다국어 Flutter 앱을 관리하는 팀
  • 협업 번역 도구를 사용하는 개발자
  • 자주 로컬라이제이션 업데이트가 있는 프로젝트
  • 개발자와 협력하는 비기술 번역가
  • 확장 가능한 국제화를 필요로 하는 앱

고려 사항

  • 적절한 권한이 있는 Google 시트에 액세스해야 합니다
  • 시트 가져오기에 인터넷 연결에 의존합니다
  • 초기 설정에는 Google Cloud와의 인증이 필요합니다
  • 오프라인 전용 번역 워크플로우에 적합하지 않습니다
  • 소스로 Google 스프레드시트만 가능(다른 플랫폼은 불가)

원본 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.