diff options
author | Hop311 <hop3114@gmail.com> | 2023-06-10 21:48:17 +0200 |
---|---|---|
committer | Hop311 <hop3114@gmail.com> | 2023-06-23 22:33:15 +0200 |
commit | 206cafc8bba310e4d4f35f4898ef3ac289abe81a (patch) | |
tree | a662b03f0f3af03b0892e2c9987c4ae128e5790f /extension/src/LoadLocalisation.cpp | |
parent | 6e26b948ea2a7632bcb7b795fe78f7169477eb6a (diff) |
Localisation and UI focus cleanup
Updated Russian localisation
Resolution, window_mode, monitor refactor
Locale based number formatting
Diffstat (limited to 'extension/src/LoadLocalisation.cpp')
-rw-r--r-- | extension/src/LoadLocalisation.cpp | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/extension/src/LoadLocalisation.cpp b/extension/src/LoadLocalisation.cpp index b660435..dc7702c 100644 --- a/extension/src/LoadLocalisation.cpp +++ b/extension/src/LoadLocalisation.cpp @@ -39,7 +39,8 @@ Error LoadLocalisation::_load_file_into_translation(String const& file_path, Ref } int line_number = 0; while (!file->eof_reached()) { - PackedStringArray line = file->get_csv_line(); + static const String delimeter = ";"; + const PackedStringArray line = file->get_csv_line(delimeter); line_number++; if (line.size() < 2 || line[0].is_empty() || line[1].is_empty()) { if (!line[0].is_empty()) { @@ -58,6 +59,10 @@ Error LoadLocalisation::_load_file_into_translation(String const& file_path, Ref Ref<Translation> LoadLocalisation::_get_translation(String const& locale) { TranslationServer* server = TranslationServer::get_singleton(); + if (server == nullptr) { + UtilityFunctions::push_error("Failed to get TranslationServer singleton"); + return nullptr; + } Ref<Translation> translation = server->get_translation_object(locale); if (translation.is_null() || translation->get_locale() != locale) { translation.instantiate(); @@ -79,12 +84,22 @@ Error LoadLocalisation::load_locale_dir(String const& dir_path, String const& lo UtilityFunctions::push_error("Locale directory does not exist: ", dir_path); return FAILED; } - Ref<Translation> translation = _get_translation(locale); + /* This will add the locale to the list of loaded locales even if it has no + * localisation files - this is useful for testing other aspects of localisation + * such as number formatting and text direction. To disable this behaviour and + * only show non-empty localisations, move the `_get_translation` call to after + * the `files.size()` check. + */ + const Ref<Translation> translation = _get_translation(locale); + const PackedStringArray files = DirAccess::get_files_at(dir_path); + if (files.size() < 1) { + UtilityFunctions::push_error("Locale directory does not contain any files: ", dir_path); + return FAILED; + } Error err = OK; - for (String const& file_name : DirAccess::get_files_at(dir_path)) { + for (String const& file_name : files) { if (file_name.get_extension().to_lower() == "csv") { - String file_path = dir_path.path_join(file_name); - if (_load_file_into_translation(file_path, translation) != OK) + if (_load_file_into_translation(dir_path.path_join(file_name), translation) != OK) err = FAILED; } } @@ -95,13 +110,22 @@ Error LoadLocalisation::load_locale_dir(String const& dir_path, String const& lo * FS-23 */ Error LoadLocalisation::load_localisation_dir(String const& dir_path) { - if(!DirAccess::dir_exists_absolute(dir_path)) { + if (!DirAccess::dir_exists_absolute(dir_path)) { UtilityFunctions::push_error("Localisation directory does not exist: ", dir_path); return FAILED; } + PackedStringArray const dirs = DirAccess::get_directories_at(dir_path); + if (dirs.size() < 1) { + UtilityFunctions::push_error("Localisation directory does not contain any sub-directories: ", dir_path); + return FAILED; + } TranslationServer* server = TranslationServer::get_singleton(); + if (server == nullptr) { + UtilityFunctions::push_error("Failed to get TranslationServer singleton"); + return FAILED; + } Error err = OK; - for (String const& locale_name : DirAccess::get_directories_at(dir_path)) { + for (String const& locale_name : dirs) { if (locale_name != server->standardize_locale(locale_name)) UtilityFunctions::push_error("Invalid locale directory name: ", locale_name); else if (load_locale_dir(dir_path.path_join(locale_name), locale_name) == OK) |