搜尋套件、儲存庫與 APP 分類

套件詳情v2.2.0

flappy_translator

一個可從 CSV 與 Excel 檔案自動產生 Flutter 本地化資源的工具。

AndroidiOSLinuxmacOSWindows
近 30 天下載
160
喜歡數
32
Pub 分數
140

安裝套件

flutter pub add flappy_translator

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Flappy Translator 是一個 Flutter 套件,可從 CSV 與 Excel 檔案自動產生翻譯資源。它透過將結構化的翻譯資料轉換為 Flutter 的地區設定檔,簡化國際化流程,減少手動操作並降低錯誤風險。適合管理多種語言的團隊使用,支援動態更新,並可無縫整合至現有工作流程。此工具確保翻譯一致性,並在不需深入理解 Flutter 國際化系統的情況下加速應用程式本地化。

適用情境

  • 自動化本地化檔案產生
  • 管理多語言應用內容
  • 簡化翻譯工作流程
  • 與 CI/CD 流水線整合
  • 無需程式碼變更即可更新翻譯
  • 與非技術翻譯人員協作

主要特色

  • 支援 CSV 和 Excel 輸入格式
  • 自動產生 Flutter 國際化檔案
  • 維持一致的鍵結構
  • 可輕鬆整合至Flutter專案
  • 提供明確的錯誤報告
  • 促進團隊協作翻譯

適合對象

  • 開發多語言應用程式的開發者
  • 使用電子表格的在地化團隊
  • 頻繁更新翻譯的項目
  • 使用自動化建構流程的團隊
  • 需要可擴展國際化功能的應用程式

使用建議

  • 需要格式正確的輸入檔案
  • 建議進行人工審核以確保準確性
  • 最好與版本控制的翻譯檔案一起使用
  • 僅限靜態翻譯資料
  • 不是即時翻譯服務
  • 依賴正確的檔案編碼

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flappy_translator

This package is discontinued and no longer maintained. No further updates, fixes or compatibility changes will be released.

Please migrate to arb_generator and Flutter's official localization tooling using flutter_localizations and intl.

Migration

ICU Placeholders

Migrate variables to ICU message syntax:

Before After
Welcome %name$s Welcome {name}
ARB Files Setup

arb_generator converts CSV translations into ARB files compatible with Flutter localization tooling.

Add the following package:

  • dart pub add --dev arb_generator

Define arb_generator package settings in pubspec.yaml:

arb_generator:
  input_filepath: "assets_dev/test.csv"
  output_directory: "lib/l10n"
  filename_prepend: "app_"

See arb_generator documentation for full example.

Flutter Localization Setup

Flutter's localization tooling generates compile-time localization delegates from ARB files.

Add the following packages:

  • flutter pub add flutter_localizations --sdk=flutter
  • flutter pub add intl:any

Enable delegate generation:

flutter:
  generate: true

in pubspec.yaml.

Add l10n.yaml file:

arb-dir: lib/l10n
template-arb-file: app_en.arb
output-dir: lib/l10n
output-localization-file: app_localizations.dart

See Flutter documentation for more information.

Generate Localization Delegates
dart run arb_generator
flutter gen-l10n
Update Delegate Usage

Use the generated AppLocalizations API instead of the old I18n API:

import '../l10n/app_localizations.dart';

Text(AppLocalizations.of(context)!.welcome('Dash')),

instead of

import 'i18n.dart';

Text(I18n.of(context).welcome(name: 'Dash')),
View Original README

A tool which automatically generates Flutter localization resources from CSV and Excel files.

This is especially useful as any team member can edit the CSV/Excel file, with the subsequent translations imported into the project via a terminal command. Basic variables (strings and integers) are supported, however neither genders nor plurals are planned to be supported. If you require such functionality, consider using arb_generator.

Getting Started

In order to use the flappy_translator package, please provide your translations in a CSV or Excel file. For CSV files, delimiters , and ; have been tested to work.

keys fr en en_GB de
plainText Bonjour le monde! Hello world! Hello world! Hallo Welt!
welcome Bienvenu %name$s! Welcome %name$s! Welcome %name$s! Willkommen %name$s!
favoriteColor Quelle est votre couleur préférée? What is your favorite color? What is your favourite colour? Was ist deine Lieblingsfarbe?

Localizations can be specified for a region by appending the country code.

Add dependency
dependencies:
  flutter_localizations:
    sdk: flutter
    
dev_dependencies: 
  flappy_translator: 
Define Settings

Settings for flappy_translator must set in your project's pubspec.yaml file. input_file_path is the only required parameter.

flappy_translator:
  input_file_path: "test.csv"
  output_dir: "lib"
  file_name: "i18n"
  class_name: "I18n"
  delimiter: ","
  start_index: 1
  depend_on_context: true
  use_single_quotes: false
  replace_no_break_spaces: false
  expose_get_string: false
  expose_loca_strings: false
  expose_locale_maps: false
  generate_comments: false
  comment_languages: []
Setting Default Description
input_file_path N/A Required. A path to the input CSV/Excel file.
output_dir lib A directory to generate the output file.
file_name i18n A filename for the generated file.
class_name I18n A class name for the generated file.
delimiter , CSV files only: a delimited to separate columns in the input CSV file.
start_index 1 The column index where translations begin (i.e. column index of default language).
depend_on_context true Whether the generated localizations should depend on BuildContext
use_single_quotes false Whether the generated file should use single or double quotes for strings.
replace_no_break_spaces false Whether no break spaces (\u00A0) should be replaced with normal spaces (\u0020).
expose_get_string false The default value for whether a getString method should be exposed.
expose_loca_strings false The default value for whether a locaStrings getter should be exposed.
expose_locale_maps false The default value for whether a localeMaps getter should be exposed.
generate_comments false Whether documentation comments should be used to display translations.
comment_languages [] Languages that are displayed in the comments. Empty -> All languages are used.
Run package

Make sure that your current working directory is the project root.

flutter pub get
dart run flappy_translator
Update iOS Info.plist

For iOS, ios/Runner/Info.plist needs to be updated with an array of the languages that the app will supports:

<key>CFBundleLocalizations</key>
<array>
  <string>fr</string>
  <string>en</string>
  <string>de</string>
</array>

For more information, see Internationalizing Flutter apps.

Use the i18n generated file

The package used your input file in order to generate a file named file_name in output_dir you provided. The following example uses the default class_name I18n with a dependency on BuildContext.

Firstly, add the I18nDelegate to your delegates:

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: const [
        I18nDelegate(),
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: I18nDelegate.supportedLocals,
      home: const Home(),
    );
  }
}

Then use the generated I18n class!

class Home extends StatelessWidget {
  const Home({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('flappy_translator'),
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text(I18n.of(context).plainText),
            Text(I18n.of(context).welcome(name: 'Dash')),
            Text(I18n.of(context).favoriteColor),
          ],
        ),
      ),
    );
  }
}

Please see example for more information.

Material Localizations

Supporting a language (i.e. ga or cy) not included in GlobalMaterialLocalizations requires adding a material localization class and delegate. Although this is out of the scope of this package, a warning is logged to the console during code generation. More info.

Rules and functionalities

Locale

Locales are specified in the top row and are expected to be given in the form en or en_US.

Default language

The column at start_index is considered the default language. This means that:

  1. If this column does not have a value, the loca key instead will be used.
  2. If another language does not have translations for a given key, the value of the default language will be used.
Keys

Each loca key must begin with a lowercase letter, after which any combinations of lowercase, uppercase, digits or underscores are valid.

Variables

In order to include variables in loca strings, they need to be written in the format %<VAR NAME>$<VAR TYPE>. Presently only integers and strings are supported as variable types.

  • %myVariable$d (d stands for an int)
  • %myVariable$s (s stands for a String)

All variables are required. Consider the key welcome from example. The generated function signature is

String welcome({
  required String name,
})

Note that if the variable's name starts with a number, the generated variable name will be var<VAR NAME>. So, for instance, %1$d would become var1.

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。