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

插件详情v0.4.1

intl_generator

包含用于处理国际化/本地化消息、日期和数字格式化与解析、双向文本以及其他国际化问题的代码。

AndroidiOSmacOSWindowsLinux
近 30 天下载
1630
喜欢数
25
Pub 分数
110

安装插件

flutter pub add intl_generator

插件介绍

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

intl_generator 包为处理 Flutter 应用中的国际化提供了代码生成工具。它支持本地化消息、日期和数字格式化、解析以及双向文本渲染。通过从消息文件生成 Dart 代码,它能够在不产生运行时开销的情况下实现高效且类型安全的本地化。该包与 intl 库无缝集成,使跨多种语言和平台管理翻译变得更加容易。

适合场景

  • 从 .arb 文件生成本地化字符串
  • 按区域设置格式化日期和数字
  • 支持从右到左的语言
  • 管理多语言应用内容
  • 自动化翻译工作流程

主要特点

  • 从 ARB 文件生成代码
  • 类型安全的本地化
  • 内置的复数支持
  • 与 intl 库集成
  • 平台无关的本地化

适合对象

  • 面向全球受众的Flutter应用
  • 管理多语言翻译的团队
  • 需要高性能本地化的项目
  • 使用 ARB 进行消息管理的开发人员
  • 需要一致的日期/数字格式的应用程序

使用建议

  • 需要设置 ARB 文件
  • 需要构建步骤进行代码生成
  • 有限的运行时自定义
  • 依赖 intl 库
  • 不适用于动态语言切换

原始 README

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

Intl_generator

This is a fork of intl_translation to have an up to date version.

If you prefer having translations as part of your build_runner process or need to support flavors, please check intl_flavors

This package provides message extraction and code generation from translated messages for the Intl package. It's a separate package so as to not require a dependency on analyzer for all users.

Extracting And Using Translated Messages

When your program contains messages that need translation, these must be extracted from the program source, sent to human translators, and the results need to be incorporated.

To extract messages, run the extract_to_arb.dart program.

  pub run intl_generator:extract_to_arb --output-dir=target/directory
      my_program.dart more_of_my_program.dart

This will produce a file intl_messages.arb with the messages from all of these programs. This is an ARB format file which can be used for input to translation tools like Localizely or (the deprecated) Google Translator Toolkit. The resulting translations can be used to generate a set of libraries using the generate_from_arb.dart program.

This expects to receive a series of files, one per locale.

pub run intl_generator:generate_from_arb --generated-file-prefix=<prefix>
    <my_dart_files> <translated_ARB_files>

This will generate Dart libraries, one per locale, which contain the translated versions. Your Dart libraries can import the primary file, named <prefix>messages_all.dart, and then call the initialization for a specific locale. Once that's done, any Intl.message calls made in the context of that locale will automatically print the translated version instead of the original.

import "my_prefix_messages_all.dart";
...
initializeMessages("dk").then(printSomeMessages);

Once the Future returned from the initialization call completes, the message data is available.

所属分类

依赖

依赖清单 7 项

源码仓库

使用此插件的项目