aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/LoadLocalisation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'extension/src/openvic-extension/LoadLocalisation.cpp')
-rw-r--r--extension/src/openvic-extension/LoadLocalisation.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/extension/src/openvic-extension/LoadLocalisation.cpp b/extension/src/openvic-extension/LoadLocalisation.cpp
index 9ab7298..ee90633 100644
--- a/extension/src/openvic-extension/LoadLocalisation.cpp
+++ b/extension/src/openvic-extension/LoadLocalisation.cpp
@@ -32,7 +32,7 @@ LoadLocalisation::~LoadLocalisation() {
singleton = nullptr;
}
-Error LoadLocalisation::_load_file_into_translation(String const& file_path, Ref<Translation> translation) const {
+Error LoadLocalisation::_load_file(String const& file_path, Ref<Translation> translation) const {
const Ref<FileAccess> file = FileAccess::open(file_path, FileAccess::ModeFlags::READ);
Error err = FileAccess::get_open_error();
if (err != OK || file.is_null()) {
@@ -46,10 +46,14 @@ Error LoadLocalisation::_load_file_into_translation(String const& file_path, Ref
line_number++;
if (line.size() < 2 || line[0].is_empty() || line[1].is_empty()) {
if (!line[0].is_empty()) {
- UtilityFunctions::push_warning("Key \"", line[0], "\" missing value on line ", line_number, " in file: ", file_path);
+ UtilityFunctions::push_warning(
+ "Key \"", line[0], "\" missing value on line ", line_number, " in file: ", file_path
+ );
err = FAILED;
} else if (line.size() >= 2 && !line[1].is_empty()) {
- UtilityFunctions::push_warning("Value \"", line[1], "\" missing key on line ", line_number, " in file: ", file_path);
+ UtilityFunctions::push_warning(
+ "Value \"", line[1], "\" missing key on line ", line_number, " in file: ", file_path
+ );
err = FAILED;
}
continue;
@@ -75,7 +79,7 @@ Ref<Translation> LoadLocalisation::_get_translation(String const& locale) const
}
Error LoadLocalisation::load_file(String const& file_path, String const& locale) const {
- return _load_file_into_translation(file_path, _get_translation(locale));
+ return _load_file(file_path, _get_translation(locale));
}
/* REQUIREMENTS
@@ -101,8 +105,9 @@ Error LoadLocalisation::load_locale_dir(String const& dir_path, String const& lo
Error err = OK;
for (String const& file_name : files) {
if (file_name.get_extension().to_lower() == "csv") {
- if (_load_file_into_translation(dir_path.path_join(file_name), translation) != OK)
+ if (_load_file(dir_path.path_join(file_name), translation) != OK) {
err = FAILED;
+ }
}
}
return err;
@@ -128,10 +133,11 @@ Error LoadLocalisation::load_localisation_dir(String const& dir_path) const {
}
Error err = OK;
for (String const& locale_name : dirs) {
- if (locale_name != server->standardize_locale(locale_name))
+ 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)
+ } else if (load_locale_dir(dir_path.path_join(locale_name), locale_name) == OK) {
continue;
+ }
err = FAILED;
}
return err;
@@ -146,12 +152,15 @@ bool LoadLocalisation::add_message(std::string_view key, Dataloader::locale_t lo
return false;
}
}
- const StringName godot_key = std_to_godot_string(std::string { key });
- const StringName godot_localisation = std_to_godot_string(std::string { localisation });
+ const StringName godot_key = Utilities::std_view_to_godot_string(key);
+ const StringName godot_localisation = Utilities::std_view_to_godot_string(localisation);
if (0) {
const StringName old_localisation = translation->get_message(godot_key);
if (!old_localisation.is_empty()) {
- UtilityFunctions::push_warning("Changing translation ", godot_key, " (", Dataloader::locale_names[locale], ") from \"", old_localisation, "\" to \"", godot_localisation, "\"");
+ UtilityFunctions::push_warning(
+ "Changing translation ", godot_key, " (", Dataloader::locale_names[locale], ") from \"",
+ old_localisation, "\" to \"", godot_localisation, "\""
+ );
}
}
translation->add_message(godot_key, godot_localisation);