Debian Codegraph @

editor/translations/editor_translation_preview_menu.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_translation_preview_menu.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_menu.h"
32
33 #include "core/string/translation_server.h"
34 #include "editor/editor_node.h"
35
36 void EditorTranslationPreviewMenu::_prepare() {
37 const String current_preview_locale = EditorNode::get_singleton()->get_preview_locale();
38
39 clear();
40 reset_size();
41
42 add_radio_check_item(TTRC("None"));
43 set_item_metadata(-1, "");
44 if (current_preview_locale.is_empty()) {
45 set_item_checked(-1, true);
46 }
47
48 add_separator();
49
50 const Vector<String> locales = TranslationServer::get_singleton()->get_loaded_locales();
51 if (locales.is_empty()) {
52 add_item(TTRC("No Translations Configured"));
53 set_item_tooltip(-1, TTRC("You can add translations in the Project Settings."));
54 set_item_disabled(-1, true);
55 return;
56 }
57
58 for (const String &locale : locales) {
59 const String name = TranslationServer::get_singleton()->get_locale_name(locale);
60 add_radio_check_item(name == locale ? name : name + " [" + locale + "]");
61 set_item_auto_translate_mode(-1, AUTO_TRANSLATE_MODE_DISABLED);
62 set_item_metadata(-1, locale);
63 if (locale == current_preview_locale) {
64 set_item_checked(-1, true);
65 }
66 }
67 }
68
69 void EditorTranslationPreviewMenu::_pressed(int p_index) {
70 for (int i = 0; i < get_item_count(); i++) {
71 set_item_checked(i, i == p_index);
72 }
73 EditorNode::get_singleton()->set_preview_locale(get_item_metadata(p_index));
74 }
75
76 void EditorTranslationPreviewMenu::_notification(int p_what) {
77 switch (p_what) {
78 case NOTIFICATION_READY: {
79 connect("about_to_popup", callable_mp(this, &EditorTranslationPreviewMenu::_prepare));
80 connect("index_pressed", callable_mp(this, &EditorTranslationPreviewMenu::_pressed));
81 } break;
82 }
83 }
84
85 EditorTranslationPreviewMenu::EditorTranslationPreviewMenu() {
86 set_hide_on_checkable_item_selection(false);
87 }