Skip to content

Commit a11efb7

Browse files
authored
Test: Make sure bundle translations works without a context id
1 parent 89c26fd commit a11efb7

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

tests/cases/translations/bundle.slint

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
out property <string> result1: make_plural1(1, @tr("Plop")) + "\n" + make_plural1(2, @tr("Flop🎃")) + "\n" + make_plural1(10, t1);
2222
out property <string> result2: make_plural2(1) + "\n" + make_plural2(-999) + "\n" + make_plural2(0) + "\n" + make_plural2(42);
2323

24+
out property <string> empty_context: @tr("" => "No-context");
25+
2426
out property <bool> test: t1 == "Hello World{}." && t2 == "Hello World." && t3 == "42 Hello World" && t4 == "43 Hello World🌍" && t5 == "Untranslated string"
2527
&& c1 == "xxaaxx"
2628
&& result1 == "there is one file in my Plop\nthere are 2 files in my Flop🎃\nthere are 10 files in my Hello World{}."
27-
&& result2 == "xx1xx\nyy-999yy\nyy0yy\nyy42yy";
29+
&& result2 == "xx1xx\nyy-999yy\nyy0yy\nyy42yy"
30+
&& empty_context == "No-context";
2831
}
2932
/*
3033
```cpp
@@ -51,24 +54,28 @@ std::transform(result2_upper.begin(), result2_upper.end(), result2_upper.begin()
5154
assert_eq(std::string_view(instance.get_result1()), result1_upper);
5255
assert_eq(std::string_view(instance.get_result2()), result2_upper);
5356
assert_eq(instance.get_t5(), "Untranslated string");
57+
assert_eq(instance.get_empty_context(), "NO-CONTEXT");
5458
assert(!instance.get_test());
5559

5660
assert(!slint::select_bundled_translation("def"));
5761
assert_eq(std::string_view(instance.get_result1()), result1_upper);
5862
assert_eq(std::string_view(instance.get_result2()), result2_upper);
5963
assert_eq(instance.get_t5(), "Untranslated string");
64+
assert_eq(instance.get_empty_context(), "NO-CONTEXT");
6065
assert(!instance.get_test());
6166

6267
assert(slint::select_bundled_translation(""));
6368
assert_eq(instance.get_result1(), result1);
6469
assert_eq(instance.get_result2(), result2);
6570
assert_eq(instance.get_t5(), "Untranslated string");
71+
assert_eq(instance.get_empty_context(), "No-context");
6672
assert(instance.get_test());
6773

6874
assert(slint::select_bundled_translation("fr"));
6975
assert_eq(instance.get_result1(), "Il y a 1 fichier dans mon Plouf\nIl y a 2 fichiers dans mon Floup🍓\nIl y a 10 fichiers dans mon Bonjour Monde{}.");
7076
assert_eq(instance.get_result2(), "rr1rr\nrr-999rr\nrr0rr\nss42ss");
7177
assert_eq(instance.get_t5(), "Untranslated string");
78+
assert_eq(instance.get_empty_context(), "Pas de contexte");
7279
assert(!instance.get_test());
7380
```
7481

@@ -92,24 +99,28 @@ assert!(slint::select_bundled_translation("up").is_ok());
9299
assert_eq!(instance.get_result1(), result1.to_uppercase());
93100
assert_eq!(instance.get_result2(), result2.to_uppercase());
94101
assert_eq!(instance.get_t5(), "Untranslated string");
102+
assert_eq!(instance.get_empty_context(), "NO-CONTEXT");
95103
assert!(!instance.get_test());
96104

97105
assert!(slint::select_bundled_translation("def").is_err());
98106
assert_eq!(instance.get_result1(), result1.to_uppercase());
99107
assert_eq!(instance.get_result2(), result2.to_uppercase());
100108
assert_eq!(instance.get_t5(), "Untranslated string");
109+
assert_eq!(instance.get_empty_context(), "NO-CONTEXT");
101110
assert!(!instance.get_test());
102111

103112
assert!(slint::select_bundled_translation("").is_ok());
104113
assert_eq!(instance.get_result1(), result1);
105114
assert_eq!(instance.get_result2(), result2);
106115
assert_eq!(instance.get_t5(), "Untranslated string");
116+
assert_eq!(instance.get_empty_context(), "No-context");
107117
assert!(instance.get_test());
108118

109119
assert!(slint::select_bundled_translation("fr").is_ok());
110120
assert_eq!(instance.get_result1(), "Il y a 1 fichier dans mon Plouf\nIl y a 2 fichiers dans mon Floup🍓\nIl y a 10 fichiers dans mon Bonjour Monde{}.");
111121
assert_eq!(instance.get_result2(), "rr1rr\nrr-999rr\nrr0rr\nss42ss");
112122
assert_eq!(instance.get_t5(), "Untranslated string");
123+
assert_eq!(instance.get_empty_context(), "Pas de contexte");
113124
assert!(!instance.get_test());
114125

115126
```

tests/cases/translations/fr/LC_MESSAGES/bundle.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,6 @@ msgctxt "TestCase"
7373
msgid "Flop🎃"
7474
msgstr "Floup🍓"
7575

76+
#: bundle.slint:24
77+
msgid "No-context"
78+
msgstr "Pas de contexte"

tests/cases/translations/up/LC_MESSAGES/bundle.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,6 @@ msgctxt "TestCase"
7373
msgid "Flop🎃"
7474
msgstr "FLOP🎃"
7575

76+
#: bundle.slint:24
77+
msgid "No-context"
78+
msgstr "NO-CONTEXT"

0 commit comments

Comments
 (0)