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

插件详情v0.0.7

localized_rich_text

一个用于简化 RichText 本地化的 Flutter 插件

AndroidiOSWeb
近 30 天下载
971
喜欢数
7
Pub 分数
140

安装插件

flutter pub add localized_rich_text

插件介绍

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

一个 Flutter 插件,旨在通过支持占位符和格式化字符串,简化 RichText 小部件的本地化,实现动态的本地化文本内容。它使开发者能够高效管理多语言富文本,确保跨平台的一致性翻译。该包与 Flutter 的本地化系统无缝集成,支持 Android、iOS 和 Web。对于需要在多种语言中呈现复杂样式文本的应用程序尤其有用。

适合场景

  • 使用占位符本地化富文本
  • 支持多语言应用内容
  • 不同语言中的动态文本格式化
  • 与 Flutter 的本地化系统集成
  • 在各种区域设置中显示样式文本

主要特点

  • 支持本地化富文本中的占位符
  • 与 Flutter 本地化的无缝集成
  • 跨语言处理格式化文本
  • 跨平台兼容性(Android、iOS、Web)
  • 用于丰富文本本地化的简单 API

适合对象

  • 包含多语言富文本内容的应用程序
  • 使用 Flutter 国际化框架的开发人员
  • 需要动态文本格式化的项目
  • 管理大规模翻译的团队
  • 需要一致的UI本地化的Web和移动应用程序

使用建议

  • 需要正确设置Flutter本地化
  • 仅限富文本场景
  • 依赖于正确的翻译文件结构
  • 可能需要对复杂的嵌套小部件进行额外处理
  • 不适用于非富文本内容

原始 README

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

A flutter plugin to facilitate the localization of a RichText.

Getting started

Install the library in your pubspec.yaml.

dependencies:
  localized_rich_text: ^0.0.7

Usage

final textToLocalize = "Hi #name, how are you?";
final userName = "Jhon";

final textSpanProperties = TextSpanProperties(
    recognizer: TapGestureRecognizer()
      ..onTap = () {
        //Do something
      },
  );
...
LocalizedRichText(
  text: textToLocalize,
  defaultTextStyle: Theme.of(context).textTheme.bodyText1!,
  keys: [
    LocalizedRichTextKey(
      key: '#name',
      value: userName,
      textStyle: Theme.of(context).textTheme.subtitle1!,
      textSpanProperties: textSpanProperties,
    ),
  ],
)

Parameters explanation

text

This must be the String to localize.
The dynamic values inside the text have to be unique, you can mark them with a special character, or you can use a unique value.

The string could be:

final textToLocalize = "Hi #name, how are you?";

or

AppLocalizations.of(context)!.title,

For more info about internationalization you can check the flutter documentation.

defaultTextStyle

This is the TextStyle used for the static words.

keys

This is the List that has to contain the dynamic values.
Each dynamic value has to be passed like an LocalizedRichTextKey object.
This list cannot be empty.

The keys will be ordered by the order in which they are been inserted in the String to localize.
This means that the order in which you pass the keys inside the keys array isn't important.

LocalizedRichText(
  ...,
  keys: [
    LocalizedRichTextKey(
      key: '#name',
      value: userName,
      textStyle: Theme.of(context).textTheme.subtitle1!,
    ),
  ],
)

所属分类

源码仓库

使用此插件的项目

暂无相关数据。