mirror of
https://gitlab.com/TheOneWithTheBraid/dart_pkpass.git
synced 2025-07-05 21:08:47 +00:00
feat: add String localization support
Signed-off-by: The one with the braid <the-one@with-the-braid.cf>
This commit is contained in:
parent
78f88305ec
commit
e345763813
10 changed files with 173 additions and 13 deletions
|
@ -6,13 +6,14 @@ import 'package:crypto/crypto.dart';
|
|||
import 'package:intl/locale.dart';
|
||||
|
||||
import 'package:pkpass/pkpass.dart';
|
||||
import 'package:pkpass/src/file_matcher.dart';
|
||||
import 'package:pkpass/src/utils/file_matcher.dart';
|
||||
import 'package:pkpass/src/utils/lproj_parser.dart';
|
||||
|
||||
final _utf8codec = Utf8Codec();
|
||||
final _jsonCodec = JsonCodec();
|
||||
|
||||
class PassFile {
|
||||
PassFile(this.metadata, this._folder);
|
||||
const PassFile(this.metadata, this._folder);
|
||||
|
||||
static Future<PassFile> parse(Uint8List pass) async {
|
||||
final codec = ZipDecoder();
|
||||
|
@ -87,6 +88,7 @@ class PassFile {
|
|||
name: name,
|
||||
scale: scale,
|
||||
locale: locale,
|
||||
extension: 'png',
|
||||
);
|
||||
if (path == null) return null;
|
||||
final file = _folder.singleWhere((element) => element.name == path);
|
||||
|
@ -96,16 +98,35 @@ class PassFile {
|
|||
|
||||
Uint8List? getBackground({Locale? locale, int scale = 1}) =>
|
||||
_matchUtf8List(name: 'background', locale: locale, scale: scale);
|
||||
|
||||
Uint8List? getFooter({Locale? locale, int scale = 1}) =>
|
||||
_matchUtf8List(name: 'footer', locale: locale, scale: scale);
|
||||
|
||||
Uint8List? getIcon({Locale? locale, int scale = 1}) =>
|
||||
_matchUtf8List(name: 'icon', locale: locale, scale: scale);
|
||||
|
||||
Uint8List? getLogo({Locale? locale, int scale = 1}) =>
|
||||
_matchUtf8List(name: 'logo', locale: locale, scale: scale);
|
||||
|
||||
Uint8List? getStrip({Locale? locale, int scale = 1}) =>
|
||||
_matchUtf8List(name: 'strip', locale: locale, scale: scale);
|
||||
|
||||
Uint8List? getThumbnail({Locale? locale, int scale = 1}) =>
|
||||
_matchUtf8List(name: 'thumbnail', locale: locale, scale: scale);
|
||||
|
||||
Map<String, String>? getLocalizations(Locale? locale) {
|
||||
final files = _folder.map((e) => e.name).toList();
|
||||
final paths = FileMatcher.matchLocale(
|
||||
files: files,
|
||||
name: 'pass',
|
||||
extension: 'strings',
|
||||
locale: locale,
|
||||
);
|
||||
print(paths);
|
||||
if (paths.isEmpty) return null;
|
||||
final file = _folder.singleWhere((element) => element.name == paths.first);
|
||||
return LProjParser.parse(file.stringContent);
|
||||
}
|
||||
}
|
||||
|
||||
extension on ArchiveFile {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue