| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/string/translation_server.h" |
| 34 |
|
| 35 |
#include "tests/test_macros.h" |
| 36 |
|
| 37 |
namespace TestTranslationServer { |
| 38 |
TEST_CASE("[TranslationServer] Translation operations") { |
| 39 |
Ref<TranslationDomain> td = TranslationServer::get_singleton()->get_or_add_domain("godot.test"); |
| 40 |
CHECK(td->get_translations().is_empty()); |
| 41 |
|
| 42 |
Ref<Translation> t1 = memnew(Translation); |
| 43 |
t1->set_locale("uk"); |
| 44 |
t1->add_message("Good Morning", String(U"Добрий ранок")); |
| 45 |
td->add_translation(t1); |
| 46 |
CHECK(td->get_translations().size() == 1); |
| 47 |
CHECK(td->has_translation_for_locale("uk", true)); |
| 48 |
CHECK(td->has_translation_for_locale("uk", false)); |
| 49 |
CHECK_FALSE(td->has_translation_for_locale("uk_UA", true)); |
| 50 |
CHECK(td->has_translation_for_locale("uk_UA", false)); |
| 51 |
CHECK(td->find_translations("uk", false).size() == 1); |
| 52 |
CHECK(td->find_translations("uk", true).size() == 1); |
| 53 |
CHECK(td->find_translations("uk_UA", false).size() == 1); |
| 54 |
CHECK(td->find_translations("uk_UA", true).size() == 0); |
| 55 |
|
| 56 |
Ref<Translation> t2 = memnew(Translation); |
| 57 |
t2->set_locale("uk_UA"); |
| 58 |
t2->add_message("Hello Godot", String(U"Привіт, Годо.")); |
| 59 |
td->add_translation(t2); |
| 60 |
CHECK(td->get_translations().size() == 2); |
| 61 |
CHECK(td->has_translation_for_locale("uk", true)); |
| 62 |
CHECK(td->has_translation_for_locale("uk", false)); |
| 63 |
CHECK(td->has_translation_for_locale("uk_UA", true)); |
| 64 |
CHECK(td->has_translation_for_locale("uk_UA", false)); |
| 65 |
CHECK(td->find_translations("uk", false).size() == 2); |
| 66 |
CHECK(td->find_translations("uk", true).size() == 1); |
| 67 |
CHECK(td->find_translations("uk_UA", false).size() == 2); |
| 68 |
CHECK(td->find_translations("uk_UA", true).size() == 1); |
| 69 |
|
| 70 |
td->set_locale_override("uk"); |
| 71 |
CHECK(td->translate("Good Morning", StringName()) == String::utf8("Добрий ранок")); |
| 72 |
|
| 73 |
td->remove_translation(t1); |
| 74 |
CHECK(td->get_translations().size() == 1); |
| 75 |
CHECK_FALSE(td->has_translation_for_locale("uk", true)); |
| 76 |
CHECK(td->has_translation_for_locale("uk", false)); |
| 77 |
CHECK(td->has_translation_for_locale("uk_UA", true)); |
| 78 |
CHECK(td->has_translation_for_locale("uk_UA", false)); |
| 79 |
CHECK(td->find_translations("uk", true).size() == 0); |
| 80 |
CHECK(td->find_translations("uk", false).size() == 1); |
| 81 |
CHECK(td->find_translations("uk_UA", true).size() == 1); |
| 82 |
CHECK(td->find_translations("uk_UA", false).size() == 1); |
| 83 |
|
| 84 |
|
| 85 |
CHECK(td->translate("Good Morning", StringName()) == "Good Morning"); |
| 86 |
|
| 87 |
TranslationServer::get_singleton()->remove_domain("godot.test"); |
| 88 |
} |
| 89 |
|
| 90 |
TEST_CASE("[TranslationServer] Locale operations") { |
| 91 |
TranslationServer *ts = TranslationServer::get_singleton(); |
| 92 |
|
| 93 |
. |
| 94 |
String loc = "es_Hani_ES_tradnl"; |
| 95 |
String res = ts->standardize_locale(loc); |
| 96 |
|
| 97 |
CHECK(res == loc); |
| 98 |
|
| 99 |
|
| 100 |
loc = "es_Hani_ES_missing"; |
| 101 |
res = ts->standardize_locale(loc); |
| 102 |
|
| 103 |
CHECK(res == "es_Hani_ES"); |
| 104 |
|
| 105 |
|
| 106 |
loc = "iw_Hani_IL"; |
| 107 |
res = ts->standardize_locale(loc); |
| 108 |
|
| 109 |
CHECK(res == "he_Hani_IL"); |
| 110 |
|
| 111 |
|
| 112 |
loc = "uk_Hani_UK"; |
| 113 |
res = ts->standardize_locale(loc); |
| 114 |
|
| 115 |
CHECK(res == "uk_Hani_GB"); |
| 116 |
|
| 117 |
|
| 118 |
loc = "de_Wrong_DE"; |
| 119 |
res = ts->standardize_locale(loc); |
| 120 |
|
| 121 |
CHECK(res == "de_DE"); |
| 122 |
|
| 123 |
|
| 124 |
loc = "es_ES"; |
| 125 |
res = ts->standardize_locale(loc, true); |
| 126 |
|
| 127 |
CHECK(res == "es_ES"); |
| 128 |
|
| 129 |
|
| 130 |
loc = "az_AZ"; |
| 131 |
res = ts->standardize_locale(loc, true); |
| 132 |
|
| 133 |
CHECK(res == "az_Latn_AZ"); |
| 134 |
|
| 135 |
|
| 136 |
loc = "pa_Arab"; |
| 137 |
res = ts->standardize_locale(loc, true); |
| 138 |
|
| 139 |
CHECK(res == "pa_Arab_PK"); |
| 140 |
|
| 141 |
|
| 142 |
loc = "zh"; |
| 143 |
res = ts->standardize_locale(loc, true); |
| 144 |
|
| 145 |
CHECK(res == "zh_Hans_CN"); |
| 146 |
|
| 147 |
|
| 148 |
loc = "zh"; |
| 149 |
res = ts->standardize_locale(loc, false); |
| 150 |
|
| 151 |
CHECK(res == "zh"); |
| 152 |
} |
| 153 |
|
| 154 |
TEST_CASE("[TranslationServer] Comparing locales") { |
| 155 |
TranslationServer *ts = TranslationServer::get_singleton(); |
| 156 |
|
| 157 |
String locale_a = "es"; |
| 158 |
String locale_b = "es"; |
| 159 |
|
| 160 |
|
| 161 |
int res = ts->compare_locales(locale_a, locale_b); |
| 162 |
|
| 163 |
CHECK(res == 10); |
| 164 |
|
| 165 |
locale_a = "sr-Latn-CS"; |
| 166 |
locale_b = "sr-Latn-RS"; |
| 167 |
|
| 168 |
|
| 169 |
res = ts->compare_locales(locale_a, locale_b); |
| 170 |
|
| 171 |
CHECK(res == 5); |
| 172 |
|
| 173 |
locale_a = "uz-Cyrl-UZ"; |
| 174 |
locale_b = "uz-Latn-UZ"; |
| 175 |
|
| 176 |
|
| 177 |
res = ts->compare_locales(locale_a, locale_b); |
| 178 |
|
| 179 |
CHECK(res == 5); |
| 180 |
|
| 181 |
locale_a = "aa-Latn-ER"; |
| 182 |
locale_b = "aa-Latn-ER-saaho"; |
| 183 |
|
| 184 |
|
| 185 |
res = ts->compare_locales(locale_a, locale_b); |
| 186 |
|
| 187 |
CHECK(res == 7); |
| 188 |
|
| 189 |
locale_a = "uz-Cyrl-UZ"; |
| 190 |
locale_b = "uz-Latn-KG"; |
| 191 |
|
| 192 |
|
| 193 |
res = ts->compare_locales(locale_a, locale_b); |
| 194 |
|
| 195 |
CHECK(res == 3); |
| 196 |
|
| 197 |
locale_a = "es-ES"; |
| 198 |
locale_b = "es-AR"; |
| 199 |
|
| 200 |
|
| 201 |
res = ts->compare_locales(locale_a, locale_b); |
| 202 |
|
| 203 |
CHECK(res == 4); |
| 204 |
|
| 205 |
locale_a = "es"; |
| 206 |
locale_b = "es-AR"; |
| 207 |
|
| 208 |
|
| 209 |
res = ts->compare_locales(locale_a, locale_b); |
| 210 |
|
| 211 |
CHECK(res == 5); |
| 212 |
|
| 213 |
locale_a = "es-EC"; |
| 214 |
locale_b = "fr-LU"; |
| 215 |
|
| 216 |
|
| 217 |
res = ts->compare_locales(locale_a, locale_b); |
| 218 |
|
| 219 |
CHECK(res == 0); |
| 220 |
|
| 221 |
locale_a = "zh-HK"; |
| 222 |
locale_b = "zh"; |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
res = ts->compare_locales(locale_a, locale_b); |
| 227 |
|
| 228 |
CHECK(res == 3); |
| 229 |
|
| 230 |
locale_a = "zh-CN"; |
| 231 |
locale_b = "zh"; |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
res = ts->compare_locales(locale_a, locale_b); |
| 236 |
|
| 237 |
CHECK(res == 10); |
| 238 |
} |
| 239 |
} |