localized_rich_text
RichText의 로컬라이제이션을 용이하게 하는 플러터 플러그인
RichText의 로컬라이제이션을 용이하게 하는 플러터 플러그인
{"sdk":"flutter"}{"sdk":"flutter"}{"sdk":"flutter"}^1.0.0아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
A flutter plugin to facilitate the localization of a RichText.
Install the library in your pubspec.yaml.
dependencies:
localized_rich_text: ^0.0.7
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,
),
],
)
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!,
),
],
)