translation.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*************************************************************************/
  2. /* translation.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef TRANSLATION_H
  30. #define TRANSLATION_H
  31. #include "resource.h"
  32. class Translation : public Resource {
  33. OBJ_TYPE( Translation, Resource );
  34. OBJ_SAVE_TYPE( Translation );
  35. RES_BASE_EXTENSION("xl");
  36. String locale;
  37. Map<StringName, StringName> translation_map;
  38. DVector<String> _get_message_list() const;
  39. DVector<String> _get_messages() const;
  40. void _set_messages(const DVector<String>& p_messages);
  41. protected:
  42. static void _bind_methods();
  43. public:
  44. void set_locale(const String& p_locale);
  45. _FORCE_INLINE_ String get_locale() const { return locale; }
  46. void add_message( const StringName& p_src_text, const StringName& p_xlated_text );
  47. virtual StringName get_message(const StringName& p_src_text) const; //overridable for other implementations
  48. void erase_message(const StringName& p_src_text);
  49. void get_message_list(List<StringName> *r_messages) const;
  50. int get_message_count() const;
  51. Translation();
  52. };
  53. class TranslationServer : public Object {
  54. OBJ_TYPE(TranslationServer, Object);
  55. String locale;
  56. String fallback;
  57. Set< Ref<Translation> > translations;
  58. bool enabled;
  59. static TranslationServer *singleton;
  60. bool _load_translations(const String& p_from);
  61. static void _bind_methods();
  62. public:
  63. _FORCE_INLINE_ static TranslationServer *get_singleton() { return singleton; }
  64. //yes, portuguese is supported!
  65. void set_enabled(bool p_enabled) { enabled=p_enabled; }
  66. _FORCE_INLINE_ bool is_enabled() const { return enabled; }
  67. void set_locale(const String& p_locale);
  68. String get_locale() const;
  69. void add_translation(const Ref<Translation> &p_translation);
  70. void remove_translation(const Ref<Translation> &p_translation);
  71. StringName translate(const StringName& p_message) const;
  72. static Vector<String> get_all_locales();
  73. static Vector<String> get_all_locale_names();
  74. void setup();
  75. void clear();
  76. void load_translations();
  77. TranslationServer();
  78. };
  79. #endif // TRANSLATION_H