搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

所在榜单