feat: add String localization support

Signed-off-by: The one with the braid <the-one@with-the-braid.cf>
This commit is contained in:
The one with the braid 2023-08-27 18:58:07 +02:00
parent 78f88305ec
commit e345763813
10 changed files with 173 additions and 13 deletions

View file

@ -1,3 +1,6 @@
import 'package:intl/locale.dart';
import 'package:pkpass/pkpass.dart';
import 'package:pkpass/src/models/barcode.dart';
import 'package:pkpass/src/utils/mabe_decode.dart';
import 'beacon.dart';
@ -191,4 +194,22 @@ class PassMetadata {
webServiceURL: json['webServiceURL'] as String?,
),
);
/// Localized version of [description] based on given [locale] and [pass].
String getLocalizedDescription(PassFile pass, Locale? locale) {
final localizations = pass.getLocalizations(locale);
return localizations?[description] ?? description;
}
/// Localized version of [organizationName] based on given [locale] and [pass].
String getLocalizedOrganizationName(PassFile pass, Locale? locale) {
final localizations = pass.getLocalizations(locale);
return localizations?[organizationName] ?? organizationName;
}
/// Localized version of [logoText] based on given [locale] and [pass].
String? getLocalizedLogoText(PassFile pass, Locale? locale) {
final localizations = pass.getLocalizations(locale);
return localizations?[logoText] ?? logoText;
}
}