| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/object/ref_counted.h" |
| 34 |
|
| 35 |
class Translation; |
| 36 |
|
| 37 |
class TranslationDomain : public RefCounted { |
| 38 |
GDCLASS(TranslationDomain, RefCounted); |
| 39 |
|
| 40 |
struct PseudolocalizationConfig { |
| 41 |
bool enabled = false; |
| 42 |
bool accents_enabled = true; |
| 43 |
bool double_vowels_enabled = false; |
| 44 |
bool fake_bidi_enabled = false; |
| 45 |
bool override_enabled = false; |
| 46 |
bool skip_placeholders_enabled = true; |
| 47 |
float expansion_ratio = 0.0; |
| 48 |
String prefix = "["; |
| 49 |
String suffix = "]"; |
| 50 |
}; |
| 51 |
|
| 52 |
bool enabled = true; |
| 53 |
|
| 54 |
String locale_override; |
| 55 |
HashSet<Ref<Translation>> translations; |
| 56 |
PseudolocalizationConfig pseudolocalization; |
| 57 |
|
| 58 |
String _get_override_string(const String &p_message) const; |
| 59 |
String _double_vowels(const String &p_message) const; |
| 60 |
String _replace_with_accented_string(const String &p_message) const; |
| 61 |
String _wrap_with_fakebidi_characters(const String &p_message) const; |
| 62 |
String _add_padding(const String &p_message, int p_length) const; |
| 63 |
const char32_t *_get_accented_version(char32_t p_character) const; |
| 64 |
bool _is_placeholder(const String &p_message, int p_index) const; |
| 65 |
|
| 66 |
protected: |
| 67 |
static void _bind_methods(); |
| 68 |
|
| 69 |
public: |
| 70 |
|
| 71 |
StringName get_message_from_translations(const String &p_locale, const StringName &p_message, const StringName &p_context) const; |
| 72 |
StringName get_message_from_translations(const String &p_locale, const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const; |
| 73 |
PackedStringArray get_loaded_locales() const; |
| 74 |
|
| 75 |
public: |
| 76 |
|
| 77 |
TypedArray<Translation> get_translations_bind() const; |
| 78 |
TypedArray<Translation> find_translations_bind(const String &p_locale, bool p_exact) const; |
| 79 |
|
| 80 |
#ifndef DISABLE_DEPRECATED |
| 81 |
Ref<Translation> get_translation_object(const String &p_locale) const; |
| 82 |
#endif |
| 83 |
|
| 84 |
void add_translation(const Ref<Translation> &p_translation); |
| 85 |
void remove_translation(const Ref<Translation> &p_translation); |
| 86 |
void clear(); |
| 87 |
|
| 88 |
bool has_translation(const Ref<Translation> &p_translation) const; |
| 89 |
const HashSet<Ref<Translation>> get_translations() const; |
| 90 |
HashSet<Ref<Translation>> find_translations(const String &p_locale, bool p_exact) const; |
| 91 |
bool has_translation_for_locale(const String &p_locale, bool p_exact) const; |
| 92 |
|
| 93 |
StringName translate(const StringName &p_message, const StringName &p_context) const; |
| 94 |
StringName translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const; |
| 95 |
|
| 96 |
String get_locale_override() const; |
| 97 |
void set_locale_override(const String &p_locale); |
| 98 |
|
| 99 |
bool is_enabled() const; |
| 100 |
void set_enabled(bool p_enabled); |
| 101 |
|
| 102 |
bool is_pseudolocalization_enabled() const; |
| 103 |
void set_pseudolocalization_enabled(bool p_enabled); |
| 104 |
bool is_pseudolocalization_accents_enabled() const; |
| 105 |
void set_pseudolocalization_accents_enabled(bool p_enabled); |
| 106 |
bool is_pseudolocalization_double_vowels_enabled() const; |
| 107 |
void set_pseudolocalization_double_vowels_enabled(bool p_enabled); |
| 108 |
bool is_pseudolocalization_fake_bidi_enabled() const; |
| 109 |
void set_pseudolocalization_fake_bidi_enabled(bool p_enabled); |
| 110 |
bool is_pseudolocalization_override_enabled() const; |
| 111 |
void set_pseudolocalization_override_enabled(bool p_enabled); |
| 112 |
bool is_pseudolocalization_skip_placeholders_enabled() const; |
| 113 |
void set_pseudolocalization_skip_placeholders_enabled(bool p_enabled); |
| 114 |
float get_pseudolocalization_expansion_ratio() const; |
| 115 |
void set_pseudolocalization_expansion_ratio(float p_ratio); |
| 116 |
String get_pseudolocalization_prefix() const; |
| 117 |
void set_pseudolocalization_prefix(const String &p_prefix); |
| 118 |
String get_pseudolocalization_suffix() const; |
| 119 |
void set_pseudolocalization_suffix(const String &p_suffix); |
| 120 |
|
| 121 |
StringName pseudolocalize(const StringName &p_message) const; |
| 122 |
}; |