From: Hamatoma Date: Tue, 1 Feb 2022 06:29:42 +0000 (+0100) Subject: I18N works X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=8a36a0cd00bf7292c513d76eed6bf170c180326f;p=exhibition.git I18N works * I18N: ** reading *.po files instead of *.mo ** fix: wrong "file exists" condition * GlobalData: added: initializing I18N * main(): calling new findConfiguration() --- diff --git a/lib/base/i18n_io.dart b/lib/base/i18n_io.dart index b490d14..e96d17c 100644 --- a/lib/base/i18n_io.dart +++ b/lib/base/i18n_io.dart @@ -54,12 +54,15 @@ class I18nIo extends I18N { void readModule(String module, [String? locale]) { locale ??= this.locale; - var file = File(join(dataDirectory, '$module.$locale.mo')); + var file = File(join(dataDirectory, '$module.$locale.po')); if (!file.existsSync() && locale.length > 2) { locale = locale.substring(0, 2); - file = File(join(dataDirectory, '$module.$locale.mo')); + file = File(join(dataDirectory, '$module.$locale.po')); } if (!file.existsSync()) { + logger.error('i18n: not found: $file'); + } else { + logger.log('reading $file', LEVEL_DETAIL); final lines = file.readAsLinesSync(); String lastKey = ''; String lastTranslation = ''; diff --git a/lib/main.dart b/lib/main.dart index 5ba9748..707fd22 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:dart_bones/dart_bones.dart'; import 'package:exhibition/base/i18n.dart'; import 'package:exhibition/setting/global_data.dart'; @@ -8,8 +10,9 @@ import 'persistence/rest_persistence.dart'; void main() async { final logger = MemoryLogger(LEVEL_FINE); ExhibitionApp.logger = logger; + // Preliminary I18n initialization. Will be replaced later: I18N.internal(logger); - final configuration = BaseConfiguration({}, logger); + final configuration = findConfiguration(logger); // We create a simplified instance. The real instance will be created in StartPage GlobalData.internal( configuration, @@ -25,3 +28,19 @@ void main() async { logger); runApp(ExhibitionApp()); } + +BaseConfiguration findConfiguration(MemoryLogger logger) { + String? path; + BaseConfiguration rc = BaseConfiguration({}, logger); + if (Platform.isLinux) { + path = '/etc/exhibition'; + } else if (Platform.isAndroid) { + path = '/etc/exhibition/exhibition.yaml'; + } else { + logger.error('main(): no supported platform. Empty configuration'); + } + if (path != null) { + rc = Configuration(path, 'exhibition.yaml', logger); + } + return rc; +} diff --git a/lib/setting/global_data.dart b/lib/setting/global_data.dart index 0a20fc0..19c8274 100644 --- a/lib/setting/global_data.dart +++ b/lib/setting/global_data.dart @@ -7,6 +7,7 @@ import 'package:path_provider/path_provider.dart'; import '../base/application_name.dart'; import '../base/defines.dart'; +import '../base/i18n_io.dart'; import '../page/page_controller_exhibition.dart'; import '../persistence/rest_persistence.dart'; import '../widget/attended_page.dart'; @@ -55,6 +56,9 @@ class GlobalData { logger.log('Start'); _instance = this; navigatorStack.globalData = this; + final i18n = I18nIo.internal( + configuration.asString('i18nDirectory', defaultValue: 'i18n')!, logger); + i18n.readModule('!global'); } Future initializeAsync() async { // Do customize!