Skip to content

Commit dcf063e

Browse files
committed
i18n: fix blank error messages when untranslated
If a message has a translation in any locale, but not all locales, then translatable_messages::translate with that message can return an empty string (instead of returning a translated string or the original untranslated string). Fix this bug in translatable_messages::translate. Also, add a test suite which exhaustively checks every translation. (I wrote this test suite for another purpose, then stumbled upon this bug. Hurray!)
1 parent 4e6cacb commit dcf063e

File tree

6 files changed

+2010
-0
lines changed

6 files changed

+2010
-0
lines changed

docs/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
quick-lint-js' version numbers are arbitrary. quick-lint-js does *not* adhere to
77
Semantic Versioning.
88

9+
## Unreleased
10+
11+
## Fixed
12+
13+
* When using the `de`, `fr_FR`, or `sv_SV` locale, some error messages are no
14+
longer blank.
15+
916
## 2.4.0 (2022-04-15)
1017

1118
[Downloads](https://c.quick-lint-js.com/releases/2.4.0/)

src/translation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ const char* translatable_messages::translate(
131131
const translation_table::mapping_entry& mapping =
132132
translation_data.mapping_table[mapping_index];
133133
std::uint32_t string_offset = mapping.string_offsets[this->locale_index_];
134+
if (string_offset == 0) {
135+
// The string has no translation.
136+
return message.c_str();
137+
}
134138
return reinterpret_cast<const char*>(translation_data.string_table +
135139
string_offset);
136140
} else {

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ quick_lint_js_add_executable(
2525
quick-lint-js/spy-lsp-endpoint-remote.h
2626
quick-lint-js/spy-lsp-message-parser.h
2727
quick-lint-js/spy-visitor.h
28+
quick-lint-js/test-translation-table-generated.h
2829
spy-visitor.cpp
2930
test-array.cpp
3031
test-assert.cpp

0 commit comments

Comments
 (0)