translation.h
1 /*************************************************************************/
2 /* translation.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 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 
32 #include "resource.h"
33 
34 
35 class Translation : public Resource {
36 
37 
38  OBJ_TYPE( Translation, Resource );
39  OBJ_SAVE_TYPE( Translation );
40  RES_BASE_EXTENSION("xl");
41 
42  String locale;
43  Map<StringName, StringName> translation_map;
44 
45  DVector<String> _get_message_list() const;
46 
47  DVector<String> _get_messages() const;
48  void _set_messages(const DVector<String>& p_messages);
49 protected:
50  static void _bind_methods();
51 
52 public:
53 
54 
55  void set_locale(const String& p_locale);
56  _FORCE_INLINE_ String get_locale() const { return locale; }
57 
58  void add_message( const StringName& p_src_text, const StringName& p_xlated_text );
59  virtual StringName get_message(const StringName& p_src_text) const; //overridable for other implementations
60  void erase_message(const StringName& p_src_text);
61 
62  void get_message_list(List<StringName> *r_messages) const;
63  int get_message_count() const;
64 
65  Translation();
66 };
67 
68 
69 class TranslationServer : public Object {
70 
71  OBJ_TYPE(TranslationServer, Object);
72 
73  String locale;
74  String fallback;
75 
76 
77  Set< Ref<Translation> > translations;
78 
79  bool enabled;
80 
81  static TranslationServer *singleton;
82  bool _load_translations(const String& p_from);
83 
84  static void _bind_methods();
85 public:
86 
87  _FORCE_INLINE_ static TranslationServer *get_singleton() { return singleton; }
88 
89  //yes, portuguese is supported!
90 
91  void set_enabled(bool p_enabled) { enabled=p_enabled; }
92  _FORCE_INLINE_ bool is_enabled() const { return enabled; }
93 
94  void set_locale(const String& p_locale);
95  String get_locale() const;
96 
97  void add_translation(const Ref<Translation> &p_translation);
98  void remove_translation(const Ref<Translation> &p_translation);
99 
100  StringName translate(const StringName& p_message) const;
101 
102  static Vector<String> get_all_locales();
103  static Vector<String> get_all_locale_names();
104 
105  void setup();
106 
107  void clear();
108 
109  void load_translations();
110 
112 };
113 
114 #endif // TRANSLATION_H
Definition: reference.h:78
Definition: set.h:44
Definition: string_db.h:48
Definition: resource.h:89
Definition: translation.h:69
Definition: dvector.h:43
Definition: ustring.h:64
Definition: object.h:317
Definition: translation.h:35