Skip to content

Commit f101d4d

Browse files
committed
Move generated translation files into res://.godot/translations
1 parent b43281c commit f101d4d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

core/string/translation.h

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class TranslationServer : public Object {
111111

112112
public:
113113
_FORCE_INLINE_ static TranslationServer *get_singleton() { return singleton; }
114+
inline static const String TRANSLATION_FILES_PATH = "res://.godot/translations";
114115

115116
void set_enabled(bool p_enabled) { enabled = p_enabled; }
116117
_FORCE_INLINE_ bool is_enabled() const { return enabled; }

editor/import/resource_importer_csv_translation.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "resource_importer_csv_translation.h"
3232

33+
#include "core/io/dir_access.h"
3334
#include "core/io/file_access.h"
3435
#include "core/io/resource_saver.h"
3536
#include "core/string/optimized_translation.h"
@@ -131,7 +132,24 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const
131132
xlt = cxl;
132133
}
133134

134-
String save_path = p_source_file.get_basename() + "." + translations[i]->get_locale() + ".translation";
135+
// `.substr(6)` strips away the leading "res://".
136+
String stripped_path = TranslationServer::TRANSLATION_FILES_PATH.plus_file(p_source_file.get_basename().substr(6));
137+
String save_path = stripped_path + "." + translations[i]->get_locale() + ".translation";
138+
139+
{
140+
// Ensure that the destination path exists.
141+
// `.substr(6)` strips away the leading "res://".
142+
String base_dir = TranslationServer::TRANSLATION_FILES_PATH.plus_file(p_source_file.get_base_dir().substr(6));
143+
DirAccess *da = DirAccess::open("res://");
144+
if (da->change_dir(base_dir) != OK) {
145+
Error err = da->make_dir_recursive(base_dir);
146+
if (err || da->change_dir(base_dir) != OK) {
147+
memdelete(da);
148+
ERR_FAIL_V_MSG(Error::ERR_CANT_CREATE, "Failed to create '" + base_dir + "' folder.");
149+
}
150+
}
151+
memdelete(da);
152+
}
135153

136154
ResourceSaver::save(save_path, xlt);
137155
if (r_gen_files) {

0 commit comments

Comments
 (0)