diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-08-28 00:06:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-28 00:06:50 +0200 |
commit | 59d1f96418540b6d1b8fec5892b3c1b7d1ae69e1 (patch) | |
tree | 42d7074ea3ca937a0d6bbd9cfba412ab3a3fcc59 /editor/import | |
parent | 7e8a7dea2e76fe4fb49f336228fb8dc7739f83fa (diff) | |
parent | 4e0d1c8f1c01f2b9562e350a1bc79e8cf8fa860a (diff) |
Merge pull request #10688 from Noshyaar/pr-csv2
ImporterCSV: add delimiter options , ; or \t
Diffstat (limited to 'editor/import')
-rw-r--r-- | editor/import/resource_importer_csv_translation.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/editor/import/resource_importer_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp index 58f0c7def0..4bbf5ba316 100644 --- a/editor/import/resource_importer_csv_translation.cpp +++ b/editor/import/resource_importer_csv_translation.cpp @@ -73,16 +73,25 @@ String ResourceImporterCSVTranslation::get_preset_name(int p_idx) const { void ResourceImporterCSVTranslation::get_import_options(List<ImportOption> *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)); } Error ResourceImporterCSVTranslation::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { bool compress = p_options["compress"]; + + String delimiter; + switch ((int)p_options["delimiter"]) { + case 0: delimiter = ","; break; + case 1: delimiter = ";"; break; + case 2: delimiter = "\t"; break; + } + FileAccessRef f = FileAccess::open(p_source_file, FileAccess::READ); ERR_FAIL_COND_V(!f, ERR_INVALID_PARAMETER); - Vector<String> line = f->get_csv_line(); + Vector<String> line = f->get_csv_line(delimiter); ERR_FAIL_COND_V(line.size() <= 1, ERR_PARSE_ERROR); Vector<String> locales; @@ -101,7 +110,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const translations.push_back(translation); } - line = f->get_csv_line(); + line = f->get_csv_line(delimiter); while (line.size() == locales.size() + 1) { @@ -113,7 +122,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const } } - line = f->get_csv_line(); + line = f->get_csv_line(delimiter); } for (int i = 0; i < translations.size(); i++) { |