1 /** 2 Server that manages all translations. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.translationserver; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.translation; 24 /** 25 Server that manages all translations. 26 27 Translations can be set to it and removed from it. 28 */ 29 @GodotBaseClass struct TranslationServerSingleton 30 { 31 package(godot) enum string _GODOT_internal_name = "TranslationServer"; 32 public: 33 @nogc nothrow: 34 union { /** */ godot_object _godot_object; /** */ GodotObject _GODOT_base; } 35 alias _GODOT_base this; 36 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 37 package(godot) __gshared bool _classBindingInitialized = false; 38 package(godot) static struct GDNativeClassBinding 39 { 40 __gshared: 41 godot_object _singleton; 42 immutable char* _singletonName = "TranslationServer"; 43 @GodotName("add_translation") GodotMethod!(void, Translation) addTranslation; 44 @GodotName("clear") GodotMethod!(void) clear; 45 @GodotName("get_loaded_locales") GodotMethod!(Array) getLoadedLocales; 46 @GodotName("get_locale") GodotMethod!(String) getLocale; 47 @GodotName("get_locale_name") GodotMethod!(String, String) getLocaleName; 48 @GodotName("remove_translation") GodotMethod!(void, Translation) removeTranslation; 49 @GodotName("set_locale") GodotMethod!(void, String) setLocale; 50 @GodotName("translate") GodotMethod!(String, String) translate; 51 } 52 /// 53 pragma(inline, true) bool opEquals(in TranslationServerSingleton other) const 54 { return _godot_object.ptr is other._godot_object.ptr; } 55 /// 56 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 57 { _godot_object.ptr = n; return null; } 58 /// 59 pragma(inline, true) bool opEquals(typeof(null) n) const 60 { return _godot_object.ptr is n; } 61 /// 62 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 63 mixin baseCasts; 64 /// Construct a new instance of TranslationServerSingleton. 65 /// Note: use `memnew!TranslationServerSingleton` instead. 66 static TranslationServerSingleton _new() 67 { 68 static godot_class_constructor constructor; 69 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("TranslationServer"); 70 if(constructor is null) return typeof(this).init; 71 return cast(TranslationServerSingleton)(constructor()); 72 } 73 @disable new(size_t s); 74 /** 75 Adds a $(D Translation) resource. 76 */ 77 void addTranslation(Translation translation) 78 { 79 checkClassBinding!(typeof(this))(); 80 ptrcall!(void)(GDNativeClassBinding.addTranslation, _godot_object, translation); 81 } 82 /** 83 Clears the server from all translations. 84 */ 85 void clear() 86 { 87 checkClassBinding!(typeof(this))(); 88 ptrcall!(void)(GDNativeClassBinding.clear, _godot_object); 89 } 90 /** 91 Returns an Array of all loaded locales of the game. 92 */ 93 Array getLoadedLocales() const 94 { 95 checkClassBinding!(typeof(this))(); 96 return ptrcall!(Array)(GDNativeClassBinding.getLoadedLocales, _godot_object); 97 } 98 /** 99 Returns the current locale of the game. 100 */ 101 String getLocale() const 102 { 103 checkClassBinding!(typeof(this))(); 104 return ptrcall!(String)(GDNativeClassBinding.getLocale, _godot_object); 105 } 106 /** 107 Returns a locale's language and its variant (e.g. `"en_US"` would return `"English (United States)"`). 108 */ 109 String getLocaleName(in String locale) const 110 { 111 checkClassBinding!(typeof(this))(); 112 return ptrcall!(String)(GDNativeClassBinding.getLocaleName, _godot_object, locale); 113 } 114 /** 115 Removes the given translation from the server. 116 */ 117 void removeTranslation(Translation translation) 118 { 119 checkClassBinding!(typeof(this))(); 120 ptrcall!(void)(GDNativeClassBinding.removeTranslation, _godot_object, translation); 121 } 122 /** 123 Sets the locale of the game. 124 */ 125 void setLocale(in String locale) 126 { 127 checkClassBinding!(typeof(this))(); 128 ptrcall!(void)(GDNativeClassBinding.setLocale, _godot_object, locale); 129 } 130 /** 131 Returns the current locale's translation for the given message (key). 132 */ 133 String translate(in String message) const 134 { 135 checkClassBinding!(typeof(this))(); 136 return ptrcall!(String)(GDNativeClassBinding.translate, _godot_object, message); 137 } 138 } 139 /// Returns: the TranslationServerSingleton 140 @property @nogc nothrow pragma(inline, true) 141 TranslationServerSingleton TranslationServer() 142 { 143 checkClassBinding!TranslationServerSingleton(); 144 return TranslationServerSingleton(TranslationServerSingleton.GDNativeClassBinding._singleton); 145 }