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

插件详情v2.0.4

fluent

Fluent 是 Project Fluent 的 Dart 实现,这是一个旨在释放自然语言表达力的本地化框架。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
2340
喜欢数
26
Pub 分数
130

安装插件

flutter pub add fluent

插件介绍

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

Fluent 是 Project Fluent 的 Dart 实现,这是一个现代的本地化框架,可实现表达性强、上下文感知的翻译。它通过强大的语法支持复杂的句子结构、复数形式和性别处理。专为国际化设计,Fluent 允许开发者以人类可读的格式编写本地化文件,从而改善开发人员与翻译人员之间的协作。它可在所有主要平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)上运行,非常适合需要丰富动态内容的跨平台应用程序。

适合场景

  • 多语言应用程序本地化
  • 动态内容的上下文感知翻译
  • 协作式翻译工作流程
  • 支持复杂语法规则
  • 跨平台国际化

主要特点

  • 自然语言表达在翻译中的应用
  • 复数和性别支持
  • 上下文感知的消息格式化
  • 可读的 .ftl 文件
  • 与 Flutter 的无缝集成

适合对象

  • 面向全球受众的应用
  • 具有非技术翻译人员的团队
  • 需要高级本地化逻辑的项目
  • Flutter 应用在多个平台
  • 开发者优先考虑可维护的国际化

使用建议

  • 需要学习 Fluent 的语法
  • 与传统框架相比,工具支持有限
  • 大型项目可能需要自定义构建步骤
  • 不适用于简单的键值翻译
  • 新项目的初始设置开销

原始 README

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

Fluent

This is a Dart runtime implementation of Project Fluent, a localization framework designed to unleash the entire expressive power of natural language translations.

Project Fluent keeps simple things simple and makes complex things possible. The syntax used for describing translations is easy to read and understand. At the same time it allows, when necessary, to represent complex concepts from natural languages like gender, plurals, conjugations, and others.

Getting Started

Learn the FTL syntax

FTL is a localization file format used for describing translation resources. FTL stands for Fluent Translation List.

FTL is designed to be simple to read, but at the same time allows to represent complex concepts from natural languages like gender, plurals, conjugations, and others.

hello-user = Hello, { $username }!

In order to use fluent.runtime, you will need to create FTL files. Read the Fluent Syntax Guide <http://projectfluent.org/fluent/guide/>_ in order to learn more about the syntax.

Using FluentBundle

Once you have some FTL files, you can generate translations using the fluent package. You start with the FluentBundle class:

import 'package:fluent/fluent.dart';

You pass a locale to the constructor:

final bundle = FluentBundle('en-GB');

You must then add messages. These would normally come from a .ftl file stored on disk, here we will just add them directly:

bundle.addMessages('''
welcome = Welcome to this great app!
greet-by-name = Hello, { $name }!
''');

To generate translations, use the format method, passing a message ID and an optional dictionary of substitution parameters. If the the message ID is not found, null is returned. Otherwise, as per the Fluent philosophy, the implementation tries hard to recover from any formatting errors and generate the most human readable representation of the value.

List<Error> errors = [];
translated = bundle.format('welcome', errors: errors)
translated = bundle.format('greet-by-name', args: {'name': 'Jane'}, errors: errors)

Custom functions

Besides the built-in NUMBER and DATETIME functions, you can register your own functions for use in translations, e.g. a PLATFORM() function used to pick a variant based on the current OS:

FluentValue platform() => FluentString('macos');
final bundle = FluentBundle('en-GB', functions: {'PLATFORM': platform});

bundle.addMessages('''
settings-menu-label = { PLATFORM() ->
    [macos] Preferences
   *[other] Settings
}
''');

A custom function receives its FTL positional and named arguments as plain Dart values (already unwrapped from FluentValue, e.g. String/num/ DateTime), and must return a FluentValue (e.g. FluentString, FluentNumber). Custom functions may also override the built-in NUMBER and DATETIME functions by registering under those names.

Known limitations and bugs

  • We do not yet support NUMBER(..., currencyDisplay="...", minimumSignificantDigits="...", maximumSignificantDigits=".. ")

  • Most options to DATETIME are not yet supported.

Help with the above would be welcome!

所属分类

依赖

依赖清单 1 项

  • intl>=0.19.0 <0.21.0

源码仓库

使用此插件的项目