Extra strings: Add no-translate tag

This commit is contained in:
Jonathan G Rennison
2023-07-30 19:27:29 +01:00
parent ebcf8b336c
commit eb03369a21
3 changed files with 18 additions and 10 deletions

View File

@@ -231,15 +231,6 @@ void FileStringReader::HandlePragma(char *str)
} else {
error("Invalid override mode %s", str + 9);
}
} else if (!memcmp(str, "override ", 9)) {
if (this->translation) error("Overrides are only allowed in the base translation.");
if (!memcmp(str + 9, "on", 2)) {
this->data.override_mode = true;
} else if (!memcmp(str + 9, "off", 3)) {
this->data.override_mode = false;
} else {
error("Invalid override mode %s", str + 9);
}
} else if (!memcmp(str, "after ", 6)) {
if (this->translation) error("Insert after is only allowed in the base translation.");
LangString *ent = this->data.Find(str + 6);
@@ -269,6 +260,15 @@ void FileStringReader::HandlePragma(char *str)
} else {
error("Can't find string to use as default translation: '%s'", str + 20);
}
} else if (!memcmp(str, "no-translate ", 13)) {
if (this->translation) error("No-translate sections are only allowed in the base translation.");
if (!memcmp(str + 13, "on", 2)) {
this->data.no_translate_mode = true;
} else if (!memcmp(str + 13, "off", 3)) {
this->data.no_translate_mode = false;
} else {
error("Invalid no-translate mode %s", str + 13);
}
} else {
StringReader::HandlePragma(str);
}

View File

@@ -37,6 +37,7 @@ struct LangString {
Case *translated_case; ///< Cases of the translation.
std::unique_ptr<LangString> chain_before;
std::unique_ptr<LangString> chain_after;
bool no_translate_mode = false;
LangString *default_translation = nullptr;
LangString(const char *name, const char *english, int index, int line);
@@ -57,6 +58,7 @@ struct StringData {
LangString *insert_before = nullptr;
LangString *insert_after = nullptr;
bool override_mode = false;
bool no_translate_mode = false;
LangString *default_translation = nullptr;
StringData(size_t tabs);

View File

@@ -770,6 +770,7 @@ void StringReader::HandleString(char *str)
/* Allocate a new LangString */
std::unique_ptr<LangString> ls(new LangString(str, s, this->data.next_string_id, _cur_line));
if (this->data.no_translate_mode) ls->no_translate_mode = true;
this->data.next_string_id = -1;
this->data.Add(str, ls.get());
@@ -796,6 +797,11 @@ void StringReader::HandleString(char *str)
return;
}
if (ent->no_translate_mode && _translation) {
strgen_error("String name '%s' is marked as no-translate", str);
return;
}
if (ent->translated && casep == nullptr) {
if (this->data.override_mode) {
free(ent->translated);
@@ -1024,7 +1030,7 @@ void LanguageWriter::WriteLang(const StringData &data)
for (uint j = 0; j != in_use[tab]; j++) {
const LangString *ls = data.strings[(tab * TAB_SIZE) + j];
if (ls != nullptr && ls->translated == nullptr && ls->default_translation == nullptr) {
if (ls != nullptr && ls->translated == nullptr && ls->default_translation == nullptr && !ls->no_translate_mode) {
_lang.missing++;
}
}