Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/string/translation_domain.h
9903 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
HashSet<Ref<Translation>> get_potential_translations(const String &p_locale) const;
75
76
public:
77
Ref<Translation> get_translation_object(const String &p_locale) const;
78
79
void add_translation(const Ref<Translation> &p_translation);
80
void remove_translation(const Ref<Translation> &p_translation);
81
void clear();
82
83
StringName translate(const StringName &p_message, const StringName &p_context) const;
84
StringName translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const;
85
86
String get_locale_override() const;
87
void set_locale_override(const String &p_locale);
88
89
bool is_enabled() const;
90
void set_enabled(bool p_enabled);
91
92
bool is_pseudolocalization_enabled() const;
93
void set_pseudolocalization_enabled(bool p_enabled);
94
bool is_pseudolocalization_accents_enabled() const;
95
void set_pseudolocalization_accents_enabled(bool p_enabled);
96
bool is_pseudolocalization_double_vowels_enabled() const;
97
void set_pseudolocalization_double_vowels_enabled(bool p_enabled);
98
bool is_pseudolocalization_fake_bidi_enabled() const;
99
void set_pseudolocalization_fake_bidi_enabled(bool p_enabled);
100
bool is_pseudolocalization_override_enabled() const;
101
void set_pseudolocalization_override_enabled(bool p_enabled);
102
bool is_pseudolocalization_skip_placeholders_enabled() const;
103
void set_pseudolocalization_skip_placeholders_enabled(bool p_enabled);
104
float get_pseudolocalization_expansion_ratio() const;
105
void set_pseudolocalization_expansion_ratio(float p_ratio);
106
String get_pseudolocalization_prefix() const;
107
void set_pseudolocalization_prefix(const String &p_prefix);
108
String get_pseudolocalization_suffix() const;
109
void set_pseudolocalization_suffix(const String &p_suffix);
110
111
StringName pseudolocalize(const StringName &p_message) const;
112
113
TranslationDomain();
114
};
115
116