Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/string/translation_domain.h
21072 views
1
/**************************************************************************/
2
/* translation_domain.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
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
// Methods in this section are not intended for scripting.
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
// These two methods are public for easier TranslationServer bindings.
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
};
123
124