| 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/string/translation.h" |
| 34 |
#include "core/string/translation_domain.h" |
| 35 |
|
| 36 |
class TranslationServer : public Object { |
| 37 |
GDCLASS(TranslationServer, Object); |
| 38 |
|
| 39 |
String locale = "en"; |
| 40 |
String fallback; |
| 41 |
|
| 42 |
Ref<TranslationDomain> main_domain; |
| 43 |
#ifdef TOOLS_ENABLED |
| 44 |
Ref<TranslationDomain> editor_domain; |
| 45 |
Ref<TranslationDomain> property_domain; |
| 46 |
Ref<TranslationDomain> doc_domain; |
| 47 |
#endif |
| 48 |
HashMap<StringName, Ref<TranslationDomain>> custom_domains; |
| 49 |
|
| 50 |
mutable HashMap<String, int> locale_compare_cache; |
| 51 |
|
| 52 |
static inline TranslationServer *singleton = nullptr; |
| 53 |
|
| 54 |
static void _bind_methods(); |
| 55 |
|
| 56 |
#ifndef DISABLE_DEPRECATED |
| 57 |
String _standardize_locale_bind_compat_98972(const String &p_locale) const; |
| 58 |
static void _bind_compatibility_methods(); |
| 59 |
#endif |
| 60 |
|
| 61 |
struct LocaleScriptInfo { |
| 62 |
String name; |
| 63 |
String script; |
| 64 |
String default_country; |
| 65 |
HashSet<String> supported_countries; |
| 66 |
}; |
| 67 |
static inline Vector<LocaleScriptInfo> locale_script_info; |
| 68 |
|
| 69 |
struct Locale { |
| 70 |
String language; |
| 71 |
String script; |
| 72 |
String country; |
| 73 |
String variant; |
| 74 |
|
| 75 |
bool operator==(const Locale &p_locale) const { |
| 76 |
return (p_locale.language == language) && |
| 77 |
(p_locale.script == script) && |
| 78 |
(p_locale.country == country) && |
| 79 |
(p_locale.variant == variant); |
| 80 |
} |
| 81 |
|
| 82 |
explicit operator String() const; |
| 83 |
|
| 84 |
Locale(const TranslationServer &p_server, const String &p_locale, bool p_add_defaults); |
| 85 |
}; |
| 86 |
|
| 87 |
static inline HashMap<String, String> language_map; |
| 88 |
static inline HashMap<String, String> script_map; |
| 89 |
static inline HashMap<String, String> locale_rename_map; |
| 90 |
static inline HashMap<String, String> country_name_map; |
| 91 |
static inline HashMap<String, String> country_rename_map; |
| 92 |
static inline HashMap<String, String> variant_map; |
| 93 |
static inline HashMap<String, String> plural_rules_map; |
| 94 |
static inline HashMap<String, int> num_system_map; |
| 95 |
static inline HashMap<String, HashSet<String>> language_script_map; |
| 96 |
|
| 97 |
void init_locale_info(); |
| 98 |
|
| 99 |
public: |
| 100 |
_FORCE_INLINE_ static TranslationServer *get_singleton() { return singleton; } |
| 101 |
|
| 102 |
|
| 103 |
Ref<TranslationDomain> get_main_domain() const { return main_domain; } |
| 104 |
#ifdef TOOLS_ENABLED |
| 105 |
Ref<TranslationDomain> get_editor_domain() const { return editor_domain; } |
| 106 |
Ref<TranslationDomain> get_property_domain() const { return property_domain; } |
| 107 |
Ref<TranslationDomain> get_doc_domain() const { return doc_domain; } |
| 108 |
#endif |
| 109 |
|
| 110 |
void set_locale(const String &p_locale); |
| 111 |
String get_locale() const; |
| 112 |
void set_fallback_locale(const String &p_locale); |
| 113 |
String get_fallback_locale() const; |
| 114 |
|
| 115 |
#ifndef DISABLE_DEPRECATED |
| 116 |
Ref<Translation> get_translation_object(const String &p_locale); |
| 117 |
#endif |
| 118 |
|
| 119 |
bool has_translation(const Ref<Translation> &p_translation) const; |
| 120 |
TypedArray<Translation> get_translations() const; |
| 121 |
TypedArray<Translation> find_translations(const String &p_locale, bool p_exact) const; |
| 122 |
bool has_translation_for_locale(const String &p_locale, bool p_exact) const; |
| 123 |
|
| 124 |
Vector<String> get_all_languages() const; |
| 125 |
String get_language_name(const String &p_language) const; |
| 126 |
|
| 127 |
Vector<String> get_all_scripts() const; |
| 128 |
String get_script_name(const String &p_script) const; |
| 129 |
|
| 130 |
Vector<String> get_all_countries() const; |
| 131 |
String get_country_name(const String &p_country) const; |
| 132 |
|
| 133 |
String get_locale_name(const String &p_locale) const; |
| 134 |
String get_plural_rules(const String &p_locale) const; |
| 135 |
|
| 136 |
bool is_script_suppored_by_locale(const String &p_locale, const String &p_script) const; |
| 137 |
|
| 138 |
PackedStringArray get_loaded_locales() const; |
| 139 |
|
| 140 |
void add_translation(const Ref<Translation> &p_translation); |
| 141 |
void remove_translation(const Ref<Translation> &p_translation); |
| 142 |
|
| 143 |
StringName translate(const StringName &p_message, const StringName &p_context = "") const; |
| 144 |
StringName translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context = "") const; |
| 145 |
|
| 146 |
StringName pseudolocalize(const StringName &p_message) const; |
| 147 |
|
| 148 |
bool is_pseudolocalization_enabled() const; |
| 149 |
void set_pseudolocalization_enabled(bool p_enabled); |
| 150 |
void reload_pseudolocalization(); |
| 151 |
|
| 152 |
String format_number(const String &p_string, const String &p_locale) const; |
| 153 |
String parse_number(const String &p_string, const String &p_locale) const; |
| 154 |
String get_percent_sign(const String &p_locale) const; |
| 155 |
|
| 156 |
String standardize_locale(const String &p_locale, bool p_add_defaults = false) const; |
| 157 |
|
| 158 |
int compare_locales(const String &p_locale_a, const String &p_locale_b) const; |
| 159 |
|
| 160 |
String get_tool_locale(); |
| 161 |
|
| 162 |
bool has_domain(const StringName &p_domain) const; |
| 163 |
Ref<TranslationDomain> get_or_add_domain(const StringName &p_domain); |
| 164 |
void remove_domain(const StringName &p_domain); |
| 165 |
|
| 166 |
void setup(); |
| 167 |
|
| 168 |
void clear(); |
| 169 |
|
| 170 |
void load_project_translations(Ref<TranslationDomain> p_domain); |
| 171 |
|
| 172 |
#ifdef TOOLS_ENABLED |
| 173 |
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override; |
| 174 |
#endif |
| 175 |
|
| 176 |
TranslationServer(); |
| 177 |
}; |