Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions core/io/translation_loader_po.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
}
if (!plural_msg.is_empty()) {
translation->add_plural_message(msg_id, plural_msg, msg_context);
translation->set_hint(msg_id, msg_context, Translation::HINT_PLURAL, msg_id_plural);
}
}
}
Expand All @@ -150,6 +151,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
Status status = STATUS_NONE;

String msg_id;
String msg_id_plural;
String msg_str;
String msg_context;
Vector<String> msgs_plural;
Expand Down Expand Up @@ -190,6 +192,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
} else if (status == STATUS_READING_PLURAL) {
ERR_FAIL_COND_V_MSG(plural_index != plural_forms - 1, Ref<Resource>(), vformat("Number of 'msgstr[]' doesn't match with number of plural forms: %s:%d.", path, line));
translation->add_plural_message(msg_id, msgs_plural, msg_context);
translation->set_hint(msg_id, msg_context, Translation::HINT_PLURAL, msg_id_plural);
}
}
msg_context = "";
Expand All @@ -204,8 +207,6 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
} else if (status != STATUS_READING_ID) {
ERR_FAIL_V_MSG(Ref<Resource>(), vformat("Unexpected 'msgid_plural', was expecting 'msgid' before 'msgid_plural' while parsing: %s:%d.", path, line));
}
// We don't record the message in "msgid_plural" itself as tr_n(), TTRN(), RTRN() interfaces provide the plural string already.
// We just have to reset variables related to plurals for "msgstr[]" later on.
l = l.substr(12).strip_edges();
plural_index = -1;
msgs_plural.clear();
Expand All @@ -221,6 +222,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
} else if (status == STATUS_READING_PLURAL) {
ERR_FAIL_COND_V_MSG(plural_index != plural_forms - 1, Ref<Resource>(), vformat("Number of 'msgstr[]' doesn't match with number of plural forms: %s:%d.", path, line));
translation->add_plural_message(msg_id, msgs_plural, msg_context);
translation->set_hint(msg_id, msg_context, Translation::HINT_PLURAL, msg_id_plural);
}
}
} else if (config.is_empty()) {
Expand All @@ -241,6 +243,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
msg_context = "";
}
msg_id = "";
msg_id_plural = "";
msg_str = "";
skip_this = skip_next;
skip_next = false;
Expand Down Expand Up @@ -298,9 +301,13 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
msg_str += l;
} else if (status == STATUS_READING_CONTEXT) {
msg_context += l;
} else if (status == STATUS_READING_PLURAL && plural_index >= 0) {
ERR_FAIL_COND_V_MSG(plural_index >= plural_forms, Ref<Resource>(), vformat("Unexpected plural form while parsing: %s:%d.", path, line));
msgs_plural.write[plural_index] = msgs_plural[plural_index] + l;
} else if (status == STATUS_READING_PLURAL) {
if (plural_index >= 0) {
ERR_FAIL_COND_V_MSG(plural_index >= plural_forms, Ref<Resource>(), vformat("Unexpected plural form while parsing: %s:%d.", path, line));
msgs_plural.write[plural_index] = msgs_plural[plural_index] + l;
} else {
msg_id_plural += l;
}
}

line++;
Expand All @@ -319,6 +326,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
if (!skip_this && !msg_id.is_empty()) {
ERR_FAIL_COND_V_MSG(plural_index != plural_forms - 1, Ref<Resource>(), vformat("Number of 'msgstr[]' doesn't match with number of plural forms: %s:%d.", path, line));
translation->add_plural_message(msg_id, msgs_plural, msg_context);
translation->set_hint(msg_id, msg_context, Translation::HINT_PLURAL, msg_id_plural);
}
}
}
Expand Down
16 changes: 6 additions & 10 deletions core/string/optimized_translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,14 @@ void OptimizedTranslation::generate(const Ref<Translation> &p_from) {

List<StringName> keys;
{
List<StringName> raw_keys;
List<MessageKey> raw_keys;
p_from->get_message_list(&raw_keys);

for (const StringName &key : raw_keys) {
const String key_str = key.operator String();
int p = key_str.find_char(0x04);
if (p == -1) {
keys.push_back(key);
for (const MessageKey &key : raw_keys) {
if (key.msgctxt.is_empty()) {
keys.push_back(key.msgid);
} else {
const String &msgctxt = key_str.substr(0, p);
const String &msgid = key_str.substr(p + 1);
WARN_PRINT(vformat("OptimizedTranslation does not support context, ignoring message '%s' with context '%s'.", msgid, msgctxt));
WARN_PRINT(vformat("OptimizedTranslation does not support context, ignoring message '%s' with context '%s'.", key.msgid, key.msgctxt));
}
}
}
Expand Down Expand Up @@ -319,7 +315,7 @@ Vector<String> OptimizedTranslation::_get_message_list() const {
return {};
}

void OptimizedTranslation::get_message_list(List<StringName> *r_messages) const {
void OptimizedTranslation::get_message_list(List<MessageKey> *r_messages) const {
WARN_PRINT_ONCE("OptimizedTranslation does not store the message texts to be translated.");
}

Expand Down
2 changes: 1 addition & 1 deletion core/string/optimized_translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class OptimizedTranslation : public Translation {
virtual Vector<String> get_translated_message_list() const override;
void generate(const Ref<Translation> &p_from);

virtual void get_message_list(List<StringName> *r_messages) const override;
virtual void get_message_list(List<MessageKey> *r_messages) const override;
virtual int get_message_count() const override;

OptimizedTranslation() {}
Expand Down
Loading