+1 vote

The real question is this one: I would like to create "expansion pack" for my game. My game is localized. So the problem is how to add new (unknowed) translations files to my game after I've loaded them from a PCK file. I've no "expansion packs" for now, so I've no Idea about how many translation files I need and their content.
Doing a couple of tests, I've found is possible to add more than one file for each language to translate it. However I don't know how to simulate, programmatically, the act of adding these files to the project, like when they are added from "project-setting" dialog.
Someone know the answer?!

in Engine by (49 points)

The funcion is simply ProjectSettings.load_resource_pack("res://mod.pck"). You can find more info here

Or the question is about loading menu for user? Then use Buttons and FileDialog.

I would like to know how to add translations files (I mean the ones with ".translation" extensions) to a project by code.
PCK files can be loaded by ProjectSettings.load_resource_pack(), as you say, but after then I need to add new translations to the one's of original project. How to do it?

1 Answer

0 votes

After loading the pack file, you also want to load the Translation resource into TranslationServer singleton.

TranslationServer.add_translation(load("path_to_translation_file.translation"))

by (18 points)

Great! Thank you very much!

Don't works... Simply add_translation require a Translation object, but loading a translation file don't give back one of that type...
At the end, I did it with this code:

func _load_translations():
var dir: Directory = Directory.new();   
var translation_array: Array = [];

if dir.open(TRANSLATION_DIRECTORY) == OK:
    var _unused = dir.list_dir_begin();
    var file_name = dir.get_next();
    while file_name != "":
        if (".csv" in file_name) and !(".import" in file_name):
            var file: File  = File.new();
            if file.open(TRANSLATION_DIRECTORY + file_name, File.READ) == OK:
                while file.get_position() < file.get_len():
                    translation_array.append(file.get_csv_line());
        file_name = dir.get_next();

    for i in range(1, translation_array.size()):
        for y in range (1, translation_array[i].size()):                
            var translation: Translation = Translation.new();

            var str_locale: String = translation_array[0][y];
            var str_origin: String = translation_array[i][0];
            var str_destination: String = translation_array[i][y];

            translation.locale = str_locale;
            translation.add_message(str_origin, str_destination);
            TranslationServer.add_translation(translation);
pass

Now I can load how many *.csv files from packages I would...

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.