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

套件詳情v2.3.0

csv_localizations

一個基於 LocalizationsDelegate 的最小 CSV 地方化套件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
103
喜歡數
8
Pub 分數
150

安裝套件

flutter pub add csv_localizations

套件介紹

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

一個輕量級的 Flutter 套件,用於使用 CSV 檔案管理應用程式翻譯,基於 LocalizationsDelegate 架構建構。它讓開發者能夠透過讀取儲存在應用程式資源中的 CSV 檔案,動態載入和切換語言翻譯。該套件透過提供一種乾淨、結構化的組織方式來處理不同語言的鍵值對,簡化了國際化,無需複雜的設定或樣板程式碼。非常適合需要簡單本地化且開銷最小的應用程式。

適用情境

  • 管理多語言應用內容
  • 從CSV文件加載翻譯
  • 支援動態語言切換
  • 簡化翻譯工作流程
  • 與現有基於資產的本地化整合
  • 輕鬆與翻譯人員協作

主要特色

  • 基於CSV的翻譯儲存
  • 基於 LocalizationsDelegate 建構
  • 最小設定需求
  • 支援多個平台
  • 與 Flutter 資產的輕鬆整合
  • 動態語言載入

適合對象

  • 小型到中型應用
  • 具有非技術翻譯人員的團隊
  • 優先考慮簡單性的專案
  • 具有靜態翻譯內容的應用程式
  • 開發者避免使用複雜的國際化解決方案
  • 使用CSV進行資料管理的項目

使用建議

  • 不太適合大規模翻譯項目
  • 需要手動管理CSV檔案
  • 對複數和格式化的支援有限
  • 無內建的翻譯編輯工具
  • 最適合簡單的鍵值翻譯
  • 不處理執行時間翻譯更新

原始 README

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

csv_localizations

A minimal CSV localization package for Flutter.

Store translations for multiple languages in a single CSV file.

One language per column - one translation per row.

Install

Add csc_localizations and flutter_localizations to your pubspec.yaml.

dependencies:
  flutter_localizations:
    sdk: flutter
  csv_localizations: <last-version>

Add a single CSV file asset to your pubspec.yaml.

flutter:
  assets:
    - assets/translations.csv

Add CsvLocalizationsDelegate and supported locales to MaterialApp.

MaterialApp(
  localizationsDelegates: [
    // delegate from flutter_localization
    ...GlobalMaterialLocalizations.delegates,
    // delegate from csv_localizations
    CsvLocalizationsDelegate(path: 'assets/translations.csv'),
  ],
  supportedLocales: [
    Locale('en'),
    Locale('nb'),
  ],
}
Note on iOS

Add supported locales to ios/Runner/Info.plist as described here

Example:

<key>CFBundleLocalizations</key>
<array>
	<string>en</string>
	<string>nb</string>
</array>

Format

A CSV file is a simple table-as-a-text-file with comma separated values as columns and new lines as rows.

In our case columns represents translations for a specific language and rows represent translations for a given key.

First row are supported language/country codes. First column are keys for localized values.

Example table:

key en nb
Hi Hi Hei
Dog Dog Hund
Cat Cat Cat

Tip (1) wrap multiline strings in quotation marks

Example CSV:

key,en,nb
Hi,Hi,Hei
Dog,Dog,Hund
Cat,Cat,Katt
my_img,assets/en.png,assets/nb.png

Tip (2) keys can point to local assets like images

API

Translate text using:

CsvLocalizations.instance.string('Hi')

Or add a String extension:

extension LocalizedString on String {
  String tr(BuildContext context) => CsvLocalizations.instance.string(this);
}

We don't want to pollute the String API by default

Now you could easily translate strings like this:

'Hi'.tr(context)

Note if a value does not exists for a given key, we return the key itself

We also support num, int and double via:

CsvLocalizations.instance.numValue('my_num')

CsvLocalizations.instance.intValue('my_int')

CsvLocalizations.instance.doubleValue('my_double')

Configurations

We support all the configurations from the csv package.

You can set it via CsvLocalizationsConfigurations when creating the CsvLocalizationsDelegate.

Here are the default configurations:

  const CsvLocalizationsConfigurations({
    this.fieldDelimiter = ',',
    this.textDelimiter = '"',
    this.textEndDelimiter = '"',
    this.eol = '\n',
    this.convertEmptyTo = '',
    this.allowInvalid = true,
    this.shouldParseNumbers = true,
  });

Example

See example

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。