excel_localization 套件讓開發者能夠透過從 Excel 檔案產生變數值來管理應用程式本地化,無需在翻譯過程中使用上下文。它透過允許團隊以熟悉的工作表格式編輯翻譯,然後自動產生程式碼資源,從而簡化國際化流程。此方法簡化了開發人員與翻譯人員之間的協作,確保在 Android、iOS、Web 和 Windows 平台上實現一致且可擴展的本地化。
適用情境
管理多語言應用內容
從電子表格生成本地化檔案
與非技術翻譯人員合作
自動化翻譯資產生成
支援跨平台本地化
主要特色
基於Excel的翻譯管理
上下文無關的本地化
自動代碼生成
跨平台支援
與 Flutter 專案的輕鬆整合
適合對象
使用外部翻譯人員的Flutter團隊
需要頻繁本地化更新的項目
尋求簡化國際化工作流程的開發者
使用結構化翻譯資料的團隊
針對多種語言的應用
使用建議
需要正確的Excel檔案格式
手動設定初始設定
與 Excel 的有限即時同步
最適合批次處理
依賴於來源資料的準確性
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
Excel Localization
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.
In order to use the excel_localization package, please provide your translations in a CSV or Excel file. For CSV files, delimiters , and ; have been tested to work.
Here you can see samle of csv how user need to arrange data
keys
fr
en
en_GB
hi
plainText
Bonjour le monde!
Hello world!
Hello world!
हैलो वर्ल्ड!
welcome
Bienvenu %name$s!
Welcome %name$s!
Welcome %name$s!
स्वागत%name$s!
favoriteColor
Quelle est votre couleur préférée?
What is your favorite color?
What is your favourite colour?
आपका पसंदीदा रंग कौनसा है?
Localizations can be specified for a region by appending the country code.
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:
classMyAppextendsStatelessWidget{
@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
navigatorKey: I18n.languageKey, //<== This is require if you like to call words without context
localizationsDelegates: [
constI18nDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: I18nDelegate.supportedLocals,
home: Home(),
);
}
}
Then use the generated I18n class!
classHomeextendsStatelessWidget{
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
appBar: AppBar(
title: Text('excel localization sample"'),
),
body: Center(
child: Column(
children: <Widget>[
Text(I18n.of(context).plainText),
Text(I18n.of(context).welcome(name: 'Simran')),
Text(I18n.of(context).favoriteColor),
// To access variable without con the way is given below just replace of(context) to translate keyword// Make sure you add navigatorkey parameter in MaterialApp or GetMaterialAppText(I18n.translate.plainText),
Text(I18n.translate.welcome(name: 'Simran')),
Text(I18n.translate.favoriteColor),
],
),
),
);
}
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:
If this column does not have a value, the loca key instead will be used.
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
Stringwelcome({
requiredString 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.
You can also watch youtube Video to understand this plugin