Solian/lib/translations.dart

26 lines
735 B
Dart
Raw Permalink Normal View History

import 'dart:convert';
import 'package:flutter/services.dart' show rootBundle;
2024-05-18 10:17:16 +00:00
import 'package:get/get.dart';
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
Map<String, Map<String, String>> get keys => messages;
2024-05-18 10:17:16 +00:00
}