Приветствую. Как преобразовать формат text.en.translation в редактируемый формат, например, text.en.csv?
Надо подключить этот перевод в проекте и сгенерировать CSV кодом.
ИИ выдал вот это:
func get_all_translations_for_locale(locale_code: String) -> Dictionary:
var all_translations := {}
# Iterate through all loaded translations in the server
# Note: TranslationServer.get_translations() is available in Godot 4.x
# For Godot 3.x, you might rely on get_translation_object() or load files directly (see below)
# In Godot 4.x:
for translation_obj in TranslationServer.get_translations():
if translation_obj.get_locale() == locale_code:
var keys = translation_obj.get_message_list()
for key in keys:
# Handle context if necessary (separated by EOT character U+0004)
var untranslated_key = key
var context = ""
var eot_pos = key.find("\u0004")
if eot_pos != -1:
context = key.substr(0, eot_pos)
untranslated_key = key.substr(eot_pos + 1)
var translated_value = translation_obj.get_message(untranslated_key, context)
all_translations[untranslated_key] = translated_value
break # Assuming one object per locale for simplicity in this method
# For both Godot 3.x and 4.x, loading resources directly is often more reliable for this
# if you have the file paths (e.g., from Project Settings localization list)
# var translation_resource = load("res://path/to/your_file.en.translation")
# if translation_resource and translation_resource.get_locale() == locale_code:
# # ... same logic as above
return all_translationsесли перевод сжатый то все плохо
This class does not store the untranslated strings for optimization purposes. Therefore, Translation.get_message_list() always returns an empty array, and Translation.get_message_count() always returns 0.
то бишь нельзя вытащить ключи, но можно попробовать следующеe:
var translation: Translation = load("res://data/translation.en.translation")
print(translation.get_message_count())
print(translation.get_message_list ())
print(translation.get_translated_message_list())
print(translation.get_translation_domain())выдает следующее
en2
0
[]
["Music", "Yes", "Are you sure whant to exit?", "Rotation", "Vibration", "No", "Quit", "Russian", "Reset", "Close", "Back to menu", "Pause", "Sound", "Touch to start game", "Are you sure whant to reset your game progress?", "English"]