mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
add more js api & improve ui
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import '../foundation/app.dart';
|
||||
|
||||
extension AppTranslation on String {
|
||||
@@ -27,10 +28,27 @@ extension AppTranslation on String {
|
||||
|
||||
static late final Map<String, Map<String, String>> translations;
|
||||
|
||||
static Future<void> init() async{
|
||||
static Future<void> init() async {
|
||||
var data = await rootBundle.load("assets/translation.json");
|
||||
var json = jsonDecode(utf8.decode(data.buffer.asUint8List()));
|
||||
translations = { for (var e in json.entries) e.key : Map<String, String>.from(e.value) };
|
||||
translations = {
|
||||
for (var e in json.entries) e.key: Map<String, String>.from(e.value)
|
||||
};
|
||||
}
|
||||
|
||||
/// Translate a string using specified comic source
|
||||
String ts(String sourceKey) {
|
||||
var comicSource = ComicSource.find(sourceKey);
|
||||
if (comicSource == null || comicSource.translations == null) {
|
||||
return this;
|
||||
}
|
||||
var locale = App.locale;
|
||||
var lc = locale.languageCode;
|
||||
var cc = locale.countryCode;
|
||||
var key = "$lc${cc == null ? "" : "_$cc"}";
|
||||
return (comicSource.translations![key] ??
|
||||
comicSource.translations![lc])?[this] ??
|
||||
this;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user