Improve error reporting when parsing CSV translation file

Fixes #46682.

Also fix unit test suite to separate generic FileAccess CSV testing
from using CSV as translation. And add more CSV translation tests.

Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
This commit is contained in:
andybarcia
2021-03-19 19:50:53 +01:00
committed by Rémi Verschelde
parent 7188ed5f91
commit 553f4f8dce
6 changed files with 54 additions and 23 deletions

View File

@ -151,7 +151,7 @@ TEST_CASE("[OptimizedTranslation] Generate from Translation and read messages")
}
#ifdef TOOLS_ENABLED
TEST_CASE("[Translation] CSV import") {
TEST_CASE("[TranslationCSV] CSV import") {
Ref<ResourceImporterCSVTranslation> import_csv_translation = memnew(ResourceImporterCSVTranslation);
HashMap<StringName, Variant> options;
@ -163,17 +163,39 @@ TEST_CASE("[Translation] CSV import") {
Error result = import_csv_translation->import(TestUtils::get_data_path("translations.csv"),
"", options, nullptr, &gen_files);
CHECK(result == OK);
CHECK(gen_files.size() == 2);
CHECK(gen_files.size() == 4);
TranslationServer *ts = TranslationServer::get_singleton();
for (const String &file : gen_files) {
Ref<Translation> translation = ResourceLoader::load(file);
CHECK(translation.is_valid());
TranslationServer::get_singleton()->add_translation(translation);
ts->add_translation(translation);
}
TranslationServer::get_singleton()->set_locale("de");
ts->set_locale("en");
CHECK(Object().tr("GOOD_MORNING", "") == "Guten Morgen");
// `tr` can be called on any Object, we reuse TranslationServer for convenience.
CHECK(ts->tr("GOOD_MORNING") == "Good Morning");
CHECK(ts->tr("GOOD_EVENING") == "Good Evening");
ts->set_locale("de");
CHECK(ts->tr("GOOD_MORNING") == "Guten Morgen");
CHECK(ts->tr("GOOD_EVENING") == "Good Evening"); // Left blank in CSV, should source from 'en'.
ts->set_locale("ja");
CHECK(ts->tr("GOOD_MORNING") == String::utf8("おはよう"));
CHECK(ts->tr("GOOD_EVENING") == String::utf8("こんばんは"));
/* FIXME: This passes, but triggers a chain reaction that makes test_viewport
* and test_text_edit explode in a billion glittery Unicode particles.
ts->set_locale("fa");
CHECK(ts->tr("GOOD_MORNING") == String::utf8("صبح بخیر"));
CHECK(ts->tr("GOOD_EVENING") == String::utf8("عصر بخیر"));
*/
}
#endif // TOOLS_ENABLED