Merge pull request #68448 from bruvzg/font_imp_tr
[Font] Add an import option to pre-render all glyphs required for the translation.
This commit is contained in:
commit
5b3a03bf5c
12 changed files with 261 additions and 20 deletions
|
|
@ -267,6 +267,39 @@ StringName OptimizedTranslation::get_message(const StringName &p_src_text, const
|
|||
}
|
||||
}
|
||||
|
||||
Vector<String> OptimizedTranslation::get_translated_message_list() const {
|
||||
Vector<String> msgs;
|
||||
|
||||
const int *htr = hash_table.ptr();
|
||||
const uint32_t *htptr = (const uint32_t *)&htr[0];
|
||||
const int *btr = bucket_table.ptr();
|
||||
const uint32_t *btptr = (const uint32_t *)&btr[0];
|
||||
const uint8_t *sr = strings.ptr();
|
||||
const char *sptr = (const char *)&sr[0];
|
||||
|
||||
for (int i = 0; i < hash_table.size(); i++) {
|
||||
uint32_t p = htptr[i];
|
||||
if (p != 0xFFFFFFFF) {
|
||||
const Bucket &bucket = *(const Bucket *)&btptr[p];
|
||||
for (int j = 0; j < bucket.size; j++) {
|
||||
if (bucket.elem[j].comp_size == bucket.elem[j].uncomp_size) {
|
||||
String rstr;
|
||||
rstr.parse_utf8(&sptr[bucket.elem[j].str_offset], bucket.elem[j].uncomp_size);
|
||||
msgs.push_back(rstr);
|
||||
} else {
|
||||
CharString uncomp;
|
||||
uncomp.resize(bucket.elem[j].uncomp_size + 1);
|
||||
smaz_decompress(&sptr[bucket.elem[j].str_offset], bucket.elem[j].comp_size, uncomp.ptrw(), bucket.elem[j].uncomp_size);
|
||||
String rstr;
|
||||
rstr.parse_utf8(uncomp.get_data());
|
||||
msgs.push_back(rstr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return msgs;
|
||||
}
|
||||
|
||||
StringName OptimizedTranslation::get_plural_message(const StringName &p_src_text, const StringName &p_plural_text, int p_n, const StringName &p_context) const {
|
||||
// The use of plurals translation is not yet supported in OptimizedTranslation.
|
||||
return get_message(p_src_text, p_context);
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ protected:
|
|||
public:
|
||||
virtual StringName get_message(const StringName &p_src_text, const StringName &p_context = "") const override; //overridable for other implementations
|
||||
virtual StringName get_plural_message(const StringName &p_src_text, const StringName &p_plural_text, int p_n, const StringName &p_context = "") const override;
|
||||
virtual Vector<String> get_translated_message_list() const override;
|
||||
void generate(const Ref<Translation> &p_from);
|
||||
|
||||
OptimizedTranslation() {}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,18 @@ Vector<String> Translation::_get_message_list() const {
|
|||
return msgs;
|
||||
}
|
||||
|
||||
Vector<String> Translation::get_translated_message_list() const {
|
||||
Vector<String> msgs;
|
||||
msgs.resize(translation_map.size());
|
||||
int idx = 0;
|
||||
for (const KeyValue<StringName, StringName> &E : translation_map) {
|
||||
msgs.set(idx, E.value);
|
||||
idx += 1;
|
||||
}
|
||||
|
||||
return msgs;
|
||||
}
|
||||
|
||||
void Translation::_set_messages(const Dictionary &p_messages) {
|
||||
List<Variant> keys;
|
||||
p_messages.get_key_list(&keys);
|
||||
|
|
@ -140,6 +152,7 @@ void Translation::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_plural_message", "src_message", "src_plural_message", "n", "context"), &Translation::get_plural_message, DEFVAL(""));
|
||||
ClassDB::bind_method(D_METHOD("erase_message", "src_message", "context"), &Translation::erase_message, DEFVAL(""));
|
||||
ClassDB::bind_method(D_METHOD("get_message_list"), &Translation::_get_message_list);
|
||||
ClassDB::bind_method(D_METHOD("get_translated_message_list"), &Translation::get_translated_message_list);
|
||||
ClassDB::bind_method(D_METHOD("get_message_count"), &Translation::get_message_count);
|
||||
ClassDB::bind_method(D_METHOD("_set_messages", "messages"), &Translation::_set_messages);
|
||||
ClassDB::bind_method(D_METHOD("_get_messages"), &Translation::_get_messages);
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ public:
|
|||
virtual void erase_message(const StringName &p_src_text, const StringName &p_context = "");
|
||||
virtual void get_message_list(List<StringName> *r_messages) const;
|
||||
virtual int get_message_count() const;
|
||||
virtual Vector<String> get_translated_message_list() const;
|
||||
|
||||
Translation() {}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -103,6 +103,23 @@ void TranslationPO::_set_messages(const Dictionary &p_messages) {
|
|||
}
|
||||
}
|
||||
|
||||
Vector<String> TranslationPO::get_translated_message_list() const {
|
||||
Vector<String> msgs;
|
||||
for (const KeyValue<StringName, HashMap<StringName, Vector<StringName>>> &E : translation_map) {
|
||||
if (E.key != StringName()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const KeyValue<StringName, Vector<StringName>> &E2 : E.value) {
|
||||
for (const StringName &E3 : E2.value) {
|
||||
msgs.push_back(E3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return msgs;
|
||||
}
|
||||
|
||||
Vector<String> TranslationPO::_get_message_list() const {
|
||||
// Return all keys in translation_map.
|
||||
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ protected:
|
|||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
Vector<String> get_translated_message_list() const override;
|
||||
void get_message_list(List<StringName> *r_messages) const override;
|
||||
int get_message_count() const override;
|
||||
void add_message(const StringName &p_src_text, const StringName &p_xlated_text, const StringName &p_context = "") override;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue