summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortpart <tpart120@proton.me>2025-01-16 20:05:48 +0100
committertpart <tpart120@proton.me>2025-01-16 20:05:53 +0100
commit9c537468b776b47f72070b0709befc49cea620c2 (patch)
tree39fea0cd2e4246d28d53cce9d10faa89c99c2779
parent74c7240f35e2d67120a674bc3d8b64caf4499b19 (diff)
downloadhurrycurry-9c537468b776b47f72070b0709befc49cea620c2.tar
hurrycurry-9c537468b776b47f72070b0709befc49cea620c2.tar.bz2
hurrycurry-9c537468b776b47f72070b0709befc49cea620c2.tar.zst
integrate localetool in the client
l---------client/locale1
l---------client/locale_book1
-rw-r--r--client/project.godot5
-rw-r--r--client/translation_manager.gd58
-rw-r--r--locale/native_language_names.ini20
5 files changed, 81 insertions, 4 deletions
diff --git a/client/locale b/client/locale
new file mode 120000
index 00000000..03036deb
--- /dev/null
+++ b/client/locale
@@ -0,0 +1 @@
+/home/timo/Source/hurrycurry/locale/ \ No newline at end of file
diff --git a/client/locale_book b/client/locale_book
new file mode 120000
index 00000000..9743557a
--- /dev/null
+++ b/client/locale_book
@@ -0,0 +1 @@
+/home/timo/Source/hurrycurry/book/locale/ \ No newline at end of file
diff --git a/client/project.godot b/client/project.godot
index 3d45924f..8c3be511 100644
--- a/client/project.godot
+++ b/client/project.godot
@@ -19,6 +19,7 @@ config/icon="res://icons/main.png"
[autoload]
+TranslationManager="*res://translation_manager.gd"
Global="*res://global.gd"
Sound="*res://audio/sound.tscn"
DisableWrongJoypads="*res://disable_wrong_joypads.gd"
@@ -213,10 +214,6 @@ menu={
]
}
-[internationalization]
-
-locale/translations=PackedStringArray("res://po/it.po", "res://po/ru.po", "res://po/ar.po", "res://po/nl.po", "res://po/de.po", "res://po/en.po", "res://po/es.po", "res://po/eu.po", "res://po/fi.po", "res://po/fr.po", "res://po/he.po", "res://po/ja.po", "res://po/pl.po", "res://po/pt.po", "res://po/tr.po", "res://po/zh_Hans.po", "res://po/zh_Hant.po", "res://po/ru.po")
-
[rendering]
renderer/rendering_method.mobile="gl_compatibility"
diff --git a/client/translation_manager.gd b/client/translation_manager.gd
new file mode 100644
index 00000000..aa9db87d
--- /dev/null
+++ b/client/translation_manager.gd
@@ -0,0 +1,58 @@
+# Hurry Curry! - a game about cooking
+# Copyright 2024 tpart
+#
+# 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.ini"
+
+var native_language_names := get_ini_dict(NATIVE_LANGUAGE_NAMES_FILE_NAME, LOCALE_PATH)
+
+func _init() -> void:
+ # Use english as fallback
+ 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") or file_name == NATIVE_LANGUAGE_NAMES_FILE_NAME:
+ 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_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_strings.has(k) else fallback_strings_book[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)
+ lines.remove_at(0)
+
+ for key in native_language_names.keys():
+ lines.append("c.settings.ui.language.%s = %s" % [key, native_language_names[key]])
+
+ for line in lines:
+ var halves := line.split("=", true, 1)
+ dict[halves[0].strip_edges()] = halves[1].strip_edges()
+
+ return dict
diff --git a/locale/native_language_names.ini b/locale/native_language_names.ini
new file mode 100644
index 00000000..a04bff18
--- /dev/null
+++ b/locale/native_language_names.ini
@@ -0,0 +1,20 @@
+[hurrycurry]
+en = English
+de = Deutsch
+fr = Français
+nl = Nederlands
+es = Español
+eu = Euskara
+ja = 日本語
+he = עִברִית
+tr = Türkçe
+fi = Suomi
+ar = العربية
+zh_Hans = 中文 (简化字)
+zh_Hant = 中文 (繁體字)
+pl = Polski
+pt = Português
+it = Italiano
+ko = 한국인
+el = ελληνικά
+ru = русский \ No newline at end of file