mirror of
https://github.com/jagandeepbrar/lunasea.git
synced 2026-08-30 20:24:25 +00:00
fix(locale): create stub primary language localization assets
This commit is contained in:
1
assets/localization/nb.json
Normal file
1
assets/localization/nb.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
1
assets/localization/zh.json
Normal file
1
assets/localization/zh.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -108,7 +108,7 @@ class _State extends State<LunaOS> {
|
||||
}
|
||||
|
||||
Future<void> _boot(Duration duration) async {
|
||||
_initLocale();
|
||||
LunaLanguage.current.use();
|
||||
_initNotifications();
|
||||
if (LunaQuickActions.isSupported) LunaQuickActions().initialize();
|
||||
|
||||
@@ -128,12 +128,6 @@ class _State extends State<LunaOS> {
|
||||
}
|
||||
}
|
||||
|
||||
void _initLocale() {
|
||||
final lan = LunaLanguage.fromLocale(context.locale) ?? LunaLanguage.ENGLISH;
|
||||
context.setLocale(lan.locale);
|
||||
Intl.defaultLocale = lan.languageTag;
|
||||
}
|
||||
|
||||
Future<void> _healthCheck() async {
|
||||
if (LunaFlavor.isStable) {
|
||||
LunaBuild().isLatestBuildVersion().then((isLatest) {
|
||||
|
||||
@@ -58,11 +58,7 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
|
||||
trailing: const LunaIconButton(icon: Icons.language_rounded),
|
||||
onTap: () async {
|
||||
final result = await SettingsDialogs().changeLanguage(context);
|
||||
if (result.item1) {
|
||||
result.item2!.use(context);
|
||||
context.setLocale(result.item2!.locale);
|
||||
// Intl.defaultLocale = result.item2!.languageTag;
|
||||
}
|
||||
if (result.item1) result.item2!.use();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -76,6 +76,11 @@ enum LunaLanguage {
|
||||
}
|
||||
|
||||
extension LunaLanguageExtension on LunaLanguage {
|
||||
Future<void> use() async {
|
||||
await LunaState.navigatorKey.currentContext!.setLocale(locale);
|
||||
Intl.defaultLocale = languageTag;
|
||||
}
|
||||
|
||||
bool get enabled {
|
||||
switch (this) {
|
||||
case LunaLanguage.ENGLISH:
|
||||
@@ -195,6 +200,4 @@ extension LunaLanguageExtension on LunaLanguage {
|
||||
return const Locale('vi');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> use(BuildContext context) => context.setLocale(this.locale);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
/// Simple dart script to concat all module's localization files into a single file for loading into LunaSea.
|
||||
/// Simple dart script to concatenate all module's localization files into a single file for loading into LunaSea.
|
||||
///
|
||||
/// This script is designed to be run from the root of the project.
|
||||
void main() {
|
||||
@@ -38,6 +38,8 @@ void main() {
|
||||
_createFile(path);
|
||||
File file = File(language.path);
|
||||
_writeFile(path, jsonDecode(file.readAsStringSync()));
|
||||
// If required, create a stub primary language to prevent asset load failures
|
||||
if (name.contains('-')) _writeStubPrimaryLanguage(_assets.path, name);
|
||||
}
|
||||
});
|
||||
print('');
|
||||
@@ -45,6 +47,12 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
void _writeStubPrimaryLanguage(String assets, String language) {
|
||||
final primary = language.split('-').first;
|
||||
final path = '$assets/$primary.json';
|
||||
_createFile(path);
|
||||
}
|
||||
|
||||
void _writeFile(String path, Map<dynamic, dynamic>? data) {
|
||||
// Read the current data in the file
|
||||
File file = File(path);
|
||||
|
||||
Reference in New Issue
Block a user