Debian Codegraph @

editor/translations/editor_translation_preview_button.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_translation_preview_button.cpp */
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 #include "editor_translation_preview_button.h"
32
33 #include "core/string/translation_server.h"
34 #include "editor/editor_node.h"
35
36 void EditorTranslationPreviewButton::_update() {
37 const String &locale = EditorNode::get_singleton()->get_preview_locale();
38
39 if (locale.is_empty()) {
40 hide();
41 return;
42 }
43
44 const String name = TranslationServer::get_singleton()->get_locale_name(locale);
45 set_text(vformat(TTR("Previewing: %s"), name == locale ? locale : name + " [" + locale + "]"));
46 show();
47 }
48
49 void EditorTranslationPreviewButton::pressed() {
50 EditorNode::get_singleton()->set_preview_locale(String());
51 }
52
53 void EditorTranslationPreviewButton::_notification(int p_what) {
54 switch (p_what) {
55 case NOTIFICATION_THEME_CHANGED: {
56 set_button_icon(get_editor_theme_icon(SNAME("Translation")));
57 } break;
58
59 case NOTIFICATION_TRANSLATION_CHANGED: {
60 _update();
61 } break;
62
63 case NOTIFICATION_READY: {
64 EditorNode::get_singleton()->connect("preview_locale_changed", callable_mp(this, &EditorTranslationPreviewButton::_update));
65 } break;
66 }
67 }
68
69 EditorTranslationPreviewButton::EditorTranslationPreviewButton() {
70 set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
71 set_tooltip_auto_translate_mode(AUTO_TRANSLATE_MODE_ALWAYS);
72 set_accessibility_name(TTRC("Disable Translation Preview"));
73 set_tooltip_text(TTRC("Previewing translation. Click to disable."));
74 set_focus_mode(FOCUS_NONE);
75 set_visible(false);
76 }