A flutter plugin to facilitate the localization of a RichText.
Install the library in your pubspec.yaml.
dependencies:
localized_rich_text: ^0.0.7final 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,
),
],
)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.
This is the TextStyle used for the static words.
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!,
),
],
)Flutter supports integrating iOS and macOS plugins through Swift Package Manager (SwiftPM). This package includes SwiftPM manifests for both platforms.
- Ensure your Flutter SDK is recent enough (this plugin requires Flutter
>=3.41.0). - Enable SwiftPM support (global):
flutter config --enable-swift-package-manager- Run your app once with Flutter to migrate the Xcode project:
flutter runFlutter falls back to CocoaPods for any plugins that don't yet support SwiftPM.
- iOS manifest: ios/localized_rich_text/Package.swift
- macOS manifest: macos/localized_rich_text/Package.swift
To validate integration end-to-end using the included example app:
cd example
flutter build ios --config-only --no-codesignNote: 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.
This plugin continues to ship .podspec files for projects that still use CocoaPods:
- iOS podspec: ios/localized_rich_text.podspec
- macOS podspec: macos/localized_rich_text.podspec