搜尋套件、儲存庫與 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

原始碼儲存庫

使用此套件的專案