Skip to content

kingace2056/localized_rich_text

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!,
    ),
  ],
)

Swift Package Manager

Flutter supports integrating iOS and macOS plugins through Swift Package Manager (SwiftPM). This package includes SwiftPM manifests for both platforms.

For app developers (using this plugin)

  1. Ensure your Flutter SDK is recent enough (this plugin requires Flutter >=3.41.0).
  2. Enable SwiftPM support (global):
flutter config --enable-swift-package-manager
  1. Run your app once with Flutter to migrate the Xcode project:
flutter run

Flutter falls back to CocoaPods for any plugins that don't yet support SwiftPM.

For plugin authors / contributors (this repo)

To validate integration end-to-end using the included example app:

cd example
flutter build ios --config-only --no-codesign

Note: this repo's example/ does not include a full macOS desktop runner. To validate macOS integration, run flutter build macos --config-only from a Flutter app that has macOS support enabled.

CocoaPods (legacy)

This plugin continues to ship .podspec files for projects that still use CocoaPods:

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors