2024-09-11 11:56:32 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:flutter/services.dart' show rootBundle;
|
2024-05-18 10:17:16 +00:00
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
2024-09-11 11:56:32 +00:00
|
|
|
class AppTranslations extends Translations {
|
|
|
|
static const List<String> supportedLocales = ['zh_cn', 'en_us'];
|
|
|
|
|
|
|
|
final Map<String, Map<String, String>> messages = {};
|
|
|
|
|
|
|
|
static Future<void> init() async {
|
|
|
|
final AppTranslations inst = Get.find();
|
|
|
|
inst.messages.clear();
|
|
|
|
for (final locale in supportedLocales) {
|
|
|
|
inst.messages[locale] = jsonDecode(
|
|
|
|
await rootBundle.loadString('assets/locales/$locale.json'),
|
|
|
|
)
|
|
|
|
.map((key, value) => MapEntry(key, value.toString()))
|
|
|
|
.cast<String, String>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-18 10:17:16 +00:00
|
|
|
@override
|
2024-09-11 11:56:32 +00:00
|
|
|
Map<String, Map<String, String>> get keys => messages;
|
2024-05-18 10:17:16 +00:00
|
|
|
}
|