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

flutter_locales 封面
套件詳情v3.0.6

flutter_locales

輕鬆將您的應用程式本地化為多種語言

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1390
喜歡數
59
Pub 分數
130

安裝套件

flutter pub add flutter_locales

套件介紹

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

flutter_locales 是一個 Flutter 套件,透過支援多種語言來簡化應用程式的本地化。它提供了一種簡單的方法來管理翻譯、動態切換區域設定,並處理語言特定的格式化。該套件與 Flutter 的國際化系統無縫整合,允許開發者定義翻譯檔案並通過簡單的鍵存取本地化字串。它支援所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,非常適合需要多語系功能的跨平台應用。

適用情境

  • 多語言應用支援
  • 動態語言切換
  • 翻譯檔案管理
  • 跨平台本地化
  • 基於用戶偏好選擇語言

主要特色

  • 簡單翻譯鍵系統
  • 執行時區域設定切換
  • 支援複數形式
  • 與 Flutter 的 i18n 集成
  • 平台無關的設計

適合對象

  • 全球移動和網頁應用
  • 面向多樣化使用者群體的應用程式
  • 新接觸本地化的開發者
  • 需要快速國際化設定的專案
  • 頻繁更新語言的應用程式

使用建議

  • 需要手動建立翻譯檔案
  • 有限的內建翻譯工具
  • 無自動字串提取
  • 最佳搭配外部翻譯服務
  • 依賴於正確的檔案結構遵循

原始 README

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

flutter_locales

Localize your Flutter app to multiple locales within seconds

Why Flutter Locales

✅ Easily Localize your app
✅ Change App Locale within the app
✅ Get Last Changed locale on App starts
✅ Save Locale Language After changed buy LocaleNotifier
✅ Get Translation with LocaleText('key') Widget

Example App

Look at a Simple app at GitHub.

Example App

Video Tutorial

Watch the video

1) Create locales assets

Create an assets/locales folder at the root of your project and add your locales json files. like: Example app assets/locales

  • your locale files name shall be name of the language
    • like:
      • en.json For english locales
      • ps.json for pashto locales

2) Include package and assets

Include latest dependency of flutter_locales

dependencies:
  flutter:
    sdk: flutter
  flutter_locales:

Include assets/locales/ folder

flutter:
  uses-material-design: true
  assets:
    - assets/locales/

3) Initialize app

Replace your main app with

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Locales.init(['en', 'fa', 'ps']); // get last saved language
  // remove await if you want to get app default language

  runApp(MyApp());
}
  • ['en', 'fa', 'ps'] are language codes of .json files located in located in assets/locales folder
  • You can replace these languages with your languages

Wrap your MaterialApp with LocaleBuilder then provide locale to app

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return LocaleBuilder(
      builder: (locale) => MaterialApp(
        title: 'Flutter Locales',
        localizationsDelegates: Locales.delegates,
        supportedLocales: Locales.supportedLocales,
        locale: locale,
        home: HomeScreen(),
      ),
    );
  }
}
  • LocaleBuilder rebuild the app you change the app locale by Locales.change(context, 'fa')

Locale Text

LocaleText Widget Use to translate a key

LocaleText(`welcome`);
  • LocaleText Translate a key to string
Locale String
  • To get a key translated call
Locales.string(context, 'welcome')

// with extension
context.localeString('welcome');

Change App Locale

To change app locale language

Locales.change(context, 'fa');

//with extension
context.changeLocale('fa');
  • When you change app automatically saves at Locale
Current Locale Language
  • To get current locale call
Locales.currentLocale(context);

//with extension
context.currentLocale;

Getting Started

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。