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

套件詳情v6.0.0

i18n_extension_core

僅適用於 Dart 的翻譯和國際化 (i18n) 套件,附帶 Dart 擴展。無論是大型專案還是小型專案,皆易於使用。

AndroidiOSLinuxmacOSWebWindows
近 30 天下載
6.9萬
喜歡數
5
Pub 分數
140

安裝套件

flutter pub add i18n_extension_core

套件介紹

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

一個僅適用於 Dart 的套件,用於簡化 Flutter 應用中的翻譯與國際化。它提供直觀的 Dart 擴展,讓本地化變得輕鬆,且程式碼樣板極少。適用於小型與大型專案,支援 Android、iOS、Web 與桌面等多個平台。此套件透過簡單語法與結構化的鍵值對,協助開發者有效管理翻譯,提升本地化字串的可讀性與可維護性。

適用情境

  • 簡單的應用本地化
  • 大規模多語言應用
  • 跨平台 Flutter 應用
  • 動態字串格式化
  • 與現有程式碼庫的輕鬆整合
  • 快速原型設計與翻譯

主要特色

  • Dart 擴展以實現簡潔語法
  • 最小化設定和樣板程式碼
  • 支援平台無關的翻譯
  • 內建字串插值
  • 可擴充的鍵值翻譯系統
  • 輕量且快速

適合對象

  • Flutter 開發者初學者的國際化
  • 管理多種語言的團隊
  • 需要快速本地化的專案
  • 偏好純 Dart 解決方案的開發者
  • 面向全球受眾的應用
  • 小型到企業級應用

使用建議

  • 無內建的翻譯管理介面
  • 需要手動維護翻譯檔案
  • 與完整框架相比,IDE 支援有限
  • 不適用於無額外邏輯的執行時間語言切換
  • 不包含翻譯檔案產生工具
  • 最好與鍵的統一命名約定一起使用

原始 README

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

pub package

i18n_extension_core

This is the core Dart-only package for the i18n_extension package.

In your Flutter app:

  • Do NOT include this core package directly.

    Instead, go to the i18n_extension package which already exports this core code, plus provides Flutter related code like the I18n widget that you must use to wrap your widget tree.

In your Dart server or Dart-only code:

  • If you are working on a Dart server-side application (backend) using frameworks such as Serverpod, Dart Frog, or Shelf, or developing a Dart-only package that does not rely on Flutter, you can use this package directly.:

    import 'package:i18n_extension_core/i18n_extension_core.dart';
    
    extension Localization on String {
      static var t = Translations.byText("en_us") + {"en_us":"Hello", "pt_br":"Hola"};
      String get i18n => localize(this, t);
    }
    
    DefaultLocale.set("es_ES");
    expect("Hello".i18n, "Hola");
    

    Note: One key use case is translating exception messages from the backend to the frontend. For example, if the backend throws an exception like: MyException('The password you typed is invalid'.i18n) it will automatically appear on the frontend as: MyException('La contraseña que ingresaste no es válida') if the user's device language is set to Spanish.

Documentation

Go to i18n_extension to read the docs.

There are only 2 differences when using this package directly:

  • Here you don't have access to the I18n widget, which is a Flutter widget.

  • The way to set the default locale is different. Instead of using the I18n widget, you must use the DefaultLocale.set() static method, like in the example above.


By Marcelo Glasberg

glasberg.dev
github.com/marcglasberg
linkedin.com/in/marcglasberg/
twitter.com/glasbergmarcelo
stackoverflow.com/users/3411681/marcg
medium.com/@marcglasberg

My article in the official Flutter documentation:

The Flutter packages I've authored:

My Medium Articles:

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

所在榜單