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

套件詳情v1.2.0

multi_language_json

一種簡單的方法,為您的Flutter應用支援多種語言!

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
39
喜歡數
21
Pub 分數
140

安裝套件

flutter pub add multi_language_json

套件介紹

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

multi_language_json 是一個 Flutter 套件,旨在簡化應用程式中的多語言支援。它透過使用 JSON 檔案有效管理翻譯,讓動態切換語言變得輕鬆。此套件支援所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,確保在各種環境中實現一致的本地化。透過最少的設定和直覺的整合,它簡化了 Flutter 應用的國際化流程。

適用情境

  • 應用本地化
  • 多語言支援
  • 動態語言切換
  • 翻譯管理
  • 跨平台應用

主要特色

  • 基於 JSON 的翻譯檔案
  • 輕鬆切換語言
  • Platform-agnostic
  • 最小設定
  • 支援所有 Flutter 平台

適合對象

  • Flutter 開發者
  • 需要多種語言的應用程式
  • 頻繁更新翻譯的項目
  • 管理本地化工作流程的團隊
  • 尋求簡單國際化解決方案的開發者

使用建議

  • 需要手動管理 JSON 檔案
  • 無內建的翻譯編輯工具
  • 僅限靜態文字翻譯
  • 不適合大規模翻譯團隊
  • 無自動回退語言處理

原始 README

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

Stream Language

Check it out at Pub.Dev

A simple way to support your Flutter application with multiple languages!

Gravar_2020_04_12_05_50_22_436

Help Maintenance

I've been maintaining quite many repos these days and burning out slowly. If you could help me cheer up, buying me a cup of coffee will make my life really happy and get much energy out of it.

Buy Me A Coffee

Getting Started

First you need create a directory in your main folder with name lang like this:

Screenshot_20

Note that each json file must have its language and country code as its name. Remember to add them to your pubspec:

Screenshot_21

In the code, to start you must first create an object with the following attributes: final language = MultiLanguageBloc( initialLanguage: 'pt_BR', defaultLanguage: 'pt_BR', commonRoute: 'common', supportedLanguages: [ 'en_US', 'pt_BR' ] );

MultiLanguageBloc is a singleton, after the first start, it will have the same attributes.

CommonRoute:

Here you enter the key within the language that contains words that can be used on more than one screen as in the example below:

Screenshot_22

The first time you use firebase language you should do this:

final language = MultiLanguageBloc(
   initialLanguage: 'pt_BR',
   defaultLanguage: 'pt_BR',
   commonRoute: 'common',
   supportedLanguages: [
     'en_US', 'pt_BR'
   ]
);

@override
Widget build(BuildContext context) {
  return MultiLanguageStart( // # Use this widget to init languages, this will only be necessary once, after that you will only use the 'MultiStreamLanguage' widget
    future: language.init(), // # Here you call the method to init
    builder: (c) => MultiStreamLanguage(
      screenRoute: ['home'],
      builder: (context, data) => Scaffold(
        appBar: AppBar(
          title: Text(d.getValue(route: ['title'])),
        ),
        body: Center(
          child: RaisedButton(
            child: Text(data.getValue(route: ['btn'])),
            onPressed: () => language.showAlertChangeLanguage(
              context: context,
              title: data.getValue(
                route: ['dialog', 'title'],
                inRoute: false
              ),
              btnNegative: data.getValue(
                  route: ['dialog', 'btn_negative'],
                  inRoute: false
              )
            ),
          ),
        ),
      )
    )
  );
}

From the next you start using only the MultiStreamLanguage widget, the first one is needed because the first app should load all language and start the default language from the user's mobile language.

Widget MultiStreamLanguage

ScreenRoute

This is where the magic happens, as a parameter it receives the screen route within the language key, see that in the code above is as: screenRoute: ['home'], in json it looks like this:

Screenshot_23

If the route were a node within 'home' you would go something like this: screenRoute: ['home', 'route_inside_home']

[Very Important] Builder -> Data

Here is the parent object to access the texts, for that use the getValue method that has route as parameter, here it will work like ScreenRoute, its second parameter is inRoute, if true, the passed route will be traveled inside the path gives wheel informed in ScreenRoute, if false, it will look in the parent route, that is, in the beginning of json, ex:

if i called data.getValue(route: ['my_route'], inRoute: true/false);

Screenshot_23

with inRoute true:

It will return: B

with inRoute false:

It will return: A

Another very interesting point, if the past route does not exist in the current language, it will search in the standard language, and if it does not exist there, it will return a string with the text 'NULL', ex:

Gravar_2020_04_12_05_49_28_636~1

Changing Language

For this, every language node must have a child named config with the following attributes:

Screenshot_18

The title key is what will appear as the language name in the dialog you select.

After that you can call the method:

language.showAlertChangeLanguage(
    context: context,
    title: 'title',
    btnNegative: 'text'
)

This will show an alert dialog like this (Language and flag listing is done automatically from the data passed in the config node):

Screenshot_19

To change the language programmatically, just call this method passing as the language prefix ex:

language.changeLanguage('pt_BR');

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。