搜索插件、代码仓与 APP 分类

插件详情v1.1.1

ez_localization

快速轻松地在您的 Flutter 应用程序中设置强大的本地化系统。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
193
喜欢数
23
Pub 分数
150

安装插件

flutter pub add ez_localization

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

ez_localization 是一个 Flutter 包,可简化强大本地化系统的设置,使开发者能够快速在应用程序中实现国际化。它支持多种语言,并提供直观的 API,用于管理 Android、iOS、Web、macOS、Windows 和 Linux 上的翻译。通过最少的配置,它可实现不同区域设置之间的无缝切换,并高效处理动态内容。该包非常适合面向全球用户的应用程序,减少样板代码,同时保持灵活性和可扩展性。

适合场景

  • 多语言应用支持
  • 轻松的翻译管理
  • 动态区域设置切换
  • 跨平台国际化
  • 简化的国际化设置
  • 面向全球用户的App本地化

主要特点

  • 所需设置最少
  • 支持所有主要平台
  • 内置语言切换
  • 简洁清晰的翻译语法
  • 可扩展的翻译文件结构
  • 自动回退到默认语言

适合对象

  • 开发多语言应用程序的开发者
  • 管理翻译工作流程的团队
  • 需要快速国际化集成的项目
  • 面向国际市场的应用
  • Flutter 初学者学习本地化
  • 频繁更新语言的项目

使用建议

  • 需要正确的翻译文件组织
  • 有限的内置翻译编辑工具
  • 手动处理复杂的复数形式
  • 依赖于正确的区域设置命名约定
  • 无内置的翻译存储或同步
  • 最佳配合结构化翻译文件使用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

EzLocalization

This package allows you to setup a powerful localization system with ease and in only a few minutes.

Features

Here are some features:

  • Easy, lightweight, open-source.
  • MIT licensed.
  • Easily extensible.

Getting started

It only takes a few steps in order to get EzLocalization to work !
First, add the following code to your MaterialApp definition (usually in main.dart) :

EzLocalizationDelegate ezLocalization = EzLocalizationDelegate(supportedLocales: [Locale('en'), Locale('fr')]); // The first language is your default language.

return MaterialApp(
  // ...
  localizationsDelegates: ezLocalization.localizationDelegates,
  supportedLocales: ezLocalization.supportedLocales,
  localeResolutionCallback: ezLocalization.localeResolutionCallback,
);

Then you create a folder named languages in your assets directory with the defined languages in it. An example structure could be :

assets
└── languages
    ├── en.json
    └── fr.json

Here's an example of en.json :

{
  "hello": "Hello !"
}

And a translated fr.json :

{
  "hello": "Bonjour !"
}

Don't forget to add the assets in your pubspec.yml :

flutter:
  # ...
  assets:
    - "assets/languages/"

That's it ! To get your string you only have to call EzLocalization.of(context)!.get('hello').

Advanced

Extension method

With the extension method, it's even easier to get a localized string ! The only thing you have to do is to replace EzLocalization.of(context)!.get('key') by context.getString('key').

You may have to manually import EzLocalization in your file.

Builder widget

EzLocalization provides a builder widget called EzLocalizationBuilder. You can use it as such :

const EzLocalizationBuilder(
  delegate: EzLocalizationDelegate(
    supportedLocales: [
      Locale('en'),
      Locale('fr'),
      Locale('es'),
    ],
  ),
  builder: (context, localizationDelegate) => MaterialApp(
    title: 'Beautifully localized app',
    home: MyMainWidget(),
    localizationsDelegates: localizationDelegate.localizationDelegates,
    supportedLocales: localizationDelegate.supportedLocales,
    localeResolutionCallback: localizationDelegate.localeResolutionCallback,
  ),
);

It has two advantages :

  • It helps reducing boilerplate.
  • You can dynamically change the current locale using EzLocalizationBuilder.of(context)!.changeLocale(yourLocale).
Nested strings

You can nest translation strings as such :

{
  "tabs": {
    "home": "Home"
  }
}

And it can be access using EzLocalization.of(context)!.get('tabs.home').

Format arguments

In your translation string, you may add arguments using {} :

{
  "greeting": "Hello {target}, my name is {me} !"
}

You can then fill them with EzLocalization.of(context)!.get('greeting', {'target': 'John', 'me': 'Bob'}). Also, instead of a map you can pass a list and get your arguments by their indexes.

Change the files path

You can change from the default path of assets/languages/$languageCode.json by passing getPathFunction to EzLocalizationDelegate. You will then have to provide a valid asset path according to the specified locale.

Don't forget to update your assets entry in your pubspec !

Updating the iOS app bundle

See the official flutter.dev documentation about updating the iOS app bundle.

Contributing

You have a lot of options to contribute to this project ! You can :

所属分类

源码仓库

使用此插件的项目

暂无相关数据。