diff options
author | metamuffin <metamuffin@disroot.org> | 2025-09-16 22:28:24 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-09-16 22:28:24 +0200 |
commit | 3f98582f903e579d9f47aba48f3976345eabe123 (patch) | |
tree | 5124f087056171ccf0196169a4b3c4e992183fa3 /client/system/translation_manager.gd | |
parent | e86637eade79ed5fef5ca2e9c169f5c40a314400 (diff) | |
download | hurrycurry-3f98582f903e579d9f47aba48f3976345eabe123.tar hurrycurry-3f98582f903e579d9f47aba48f3976345eabe123.tar.bz2 hurrycurry-3f98582f903e579d9f47aba48f3976345eabe123.tar.zst |
Move some scripts to new "system" dir, add argument parser
Diffstat (limited to 'client/system/translation_manager.gd')
-rw-r--r-- | client/system/translation_manager.gd | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/client/system/translation_manager.gd b/client/system/translation_manager.gd new file mode 100644 index 00000000..9aa374b2 --- /dev/null +++ b/client/system/translation_manager.gd @@ -0,0 +1,57 @@ +# Hurry Curry! - a game about cooking +# Copyright (C) 2025 Hurry Curry! contributors +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License only. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +extends Node + +const LOCALE_PATH := "res://locale/" +const LOCALE_BOOK_PATH := "res://locale_book/" +const NATIVE_LANGUAGE_NAMES_FILE_NAME := "native_language_names.ini1" + +func _init() -> void: + # Use english as fallback + var native_language_names := get_ini_dict(NATIVE_LANGUAGE_NAMES_FILE_NAME, LOCALE_PATH) + var fallback_strings := get_ini_dict("en.ini", LOCALE_PATH) + var fallback_strings_book := get_ini_dict("en.ini", LOCALE_BOOK_PATH) + + for file_name in DirAccess.get_files_at(LOCALE_PATH): + if !file_name.ends_with(".ini"): + continue + + var translation := Translation.new() + translation.locale = file_name.trim_suffix(".ini") + var trans_strings := get_ini_dict(file_name, LOCALE_PATH) + var trans_book_strings := get_ini_dict(file_name, LOCALE_BOOK_PATH) + + for k in fallback_strings.keys(): + translation.add_message(k, trans_strings[k] if trans_strings.has(k) else fallback_strings[k]) + for k in fallback_strings_book.keys(): + translation.add_message(k, trans_book_strings[k] if trans_book_strings.has(k) else fallback_strings_book[k]) + for k in native_language_names.keys(): + translation.add_message("c.settings.ui.language.%s" % k, native_language_names[k]) + + TranslationServer.add_translation(translation) + + +func get_ini_dict(file_name: String, locale_path: String) -> Dictionary: # Dictionary[String, String] + var dict := {} + var lines := FileAccess.get_file_as_string(locale_path + file_name).split("\n", false) + if lines.size() > 0: + lines.remove_at(0) + + for line in lines: + var halves := line.split("=", true, 1) + dict[halves[0].strip_edges()] = halves[1].strip_edges().replace("%n", "\n") + + return dict |