diff --git a/doc/classes/ResourceImporterCSVTranslation.xml b/doc/classes/ResourceImporterCSVTranslation.xml index 578a79fdca9..b9af51fb3eb 100644 --- a/doc/classes/ResourceImporterCSVTranslation.xml +++ b/doc/classes/ResourceImporterCSVTranslation.xml @@ -24,5 +24,11 @@ The delimiter to use in the CSV file. The default value matches the common CSV convention. Tab-separated values are sometimes called TSV files. + + If [code]true[/code], message keys in the CSV file are unescaped using [method String.c_unescape] during the import process. + + + If [code]true[/code], message translations in the CSV file are unescaped using [method String.c_unescape] during the import process. + diff --git a/editor/import/resource_importer_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp index c1810114022..a5c5d6b09c5 100644 --- a/editor/import/resource_importer_csv_translation.cpp +++ b/editor/import/resource_importer_csv_translation.cpp @@ -70,10 +70,14 @@ String ResourceImporterCSVTranslation::get_preset_name(int p_idx) const { void ResourceImporterCSVTranslation::get_import_options(const String &p_path, List *r_options, int p_preset) const { r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress"), true)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "delimiter", PROPERTY_HINT_ENUM, "Comma,Semicolon,Tab"), 0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "unescape_keys"), false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "unescape_translations"), true)); } Error ResourceImporterCSVTranslation::import(const String &p_source_file, const String &p_save_path, const HashMap &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - bool compress = p_options["compress"]; + const bool compress = p_options["compress"]; + const bool unescape_keys = p_options.has("unescape_keys") ? bool(p_options["unescape_keys"]) : false; + const bool unescape_translations = p_options.has("unescape_translations") ? bool(p_options["unescape_translations"]) : true; String delimiter; switch ((int)p_options["delimiter"]) { @@ -118,7 +122,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const do { line = f->get_csv_line(delimiter); - String key = line[0]; + const String key = unescape_keys ? line[0].c_unescape() : line[0]; if (!key.is_empty()) { ERR_CONTINUE_MSG(line.size() != locales.size() + (int)skipped_locales.size() + 1, vformat("Error importing CSV translation: expected %d locale(s), but the '%s' key has %d locale(s).", locales.size(), key, line.size() - 1)); @@ -127,7 +131,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const if (skipped_locales.has(i)) { continue; } - translations.write[write_index++]->add_message(key, line[i].c_unescape()); + translations.write[write_index++]->add_message(key, unescape_translations ? line[i].c_unescape() : line[i]); } } } while (!f->eof_reached());