translation_domain.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #ifndef TRANSLATION_DOMAIN_H
  31. #define TRANSLATION_DOMAIN_H
  32. #include "core/object/ref_counted.h"
  33. class Translation;
  34. class TranslationDomain : public RefCounted {
  35. GDCLASS(TranslationDomain, RefCounted);
  36. struct PseudolocalizationConfig {
  37. bool enabled = false;
  38. bool accents_enabled = true;
  39. bool double_vowels_enabled = false;
  40. bool fake_bidi_enabled = false;
  41. bool override_enabled = false;
  42. bool skip_placeholders_enabled = true;
  43. float expansion_ratio = 0.0;
  44. String prefix = "[";
  45. String suffix = "]";
  46. };
  47. HashSet<Ref<Translation>> translations;
  48. PseudolocalizationConfig pseudolocalization;
  49. String _get_override_string(const String &p_message) const;
  50. String _double_vowels(const String &p_message) const;
  51. String _replace_with_accented_string(const String &p_message) const;
  52. String _wrap_with_fakebidi_characters(const String &p_message) const;
  53. String _add_padding(const String &p_message, int p_length) const;
  54. const char32_t *_get_accented_version(char32_t p_character) const;
  55. bool _is_placeholder(const String &p_message, int p_index) const;
  56. protected:
  57. static void _bind_methods();
  58. public:
  59. // Methods in this section are not intended for scripting.
  60. StringName get_message_from_translations(const String &p_locale, const StringName &p_message, const StringName &p_context) const;
  61. 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;
  62. PackedStringArray get_loaded_locales() const;
  63. public:
  64. Ref<Translation> get_translation_object(const String &p_locale) const;
  65. void add_translation(const Ref<Translation> &p_translation);
  66. void remove_translation(const Ref<Translation> &p_translation);
  67. void clear();
  68. StringName translate(const StringName &p_message, const StringName &p_context) const;
  69. StringName translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const;
  70. bool is_pseudolocalization_enabled() const;
  71. void set_pseudolocalization_enabled(bool p_enabled);
  72. bool is_pseudolocalization_accents_enabled() const;
  73. void set_pseudolocalization_accents_enabled(bool p_enabled);
  74. bool is_pseudolocalization_double_vowels_enabled() const;
  75. void set_pseudolocalization_double_vowels_enabled(bool p_enabled);
  76. bool is_pseudolocalization_fake_bidi_enabled() const;
  77. void set_pseudolocalization_fake_bidi_enabled(bool p_enabled);
  78. bool is_pseudolocalization_override_enabled() const;
  79. void set_pseudolocalization_override_enabled(bool p_enabled);
  80. bool is_pseudolocalization_skip_placeholders_enabled() const;
  81. void set_pseudolocalization_skip_placeholders_enabled(bool p_enabled);
  82. float get_pseudolocalization_expansion_ratio() const;
  83. void set_pseudolocalization_expansion_ratio(float p_ratio);
  84. String get_pseudolocalization_prefix() const;
  85. void set_pseudolocalization_prefix(const String &p_prefix);
  86. String get_pseudolocalization_suffix() const;
  87. void set_pseudolocalization_suffix(const String &p_suffix);
  88. StringName pseudolocalize(const StringName &p_message) const;
  89. TranslationDomain();
  90. };
  91. #endif // TRANSLATION_DOMAIN_H