Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/translations/editor_translation_preview_menu.cpp
9896 views
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
const Vector<String> locales = TranslationServer::get_singleton()->get_loaded_locales();
49
if (!locales.is_empty()) {
50
add_separator();
51
}
52
for (const String &locale : locales) {
53
const String name = TranslationServer::get_singleton()->get_locale_name(locale);
54
add_radio_check_item(name == locale ? name : name + " [" + locale + "]");
55
set_item_auto_translate_mode(-1, AUTO_TRANSLATE_MODE_DISABLED);
56
set_item_metadata(-1, locale);
57
if (locale == current_preview_locale) {
58
set_item_checked(-1, true);
59
}
60
}
61
}
62
63
void EditorTranslationPreviewMenu::_pressed(int p_index) {
64
for (int i = 0; i < get_item_count(); i++) {
65
set_item_checked(i, i == p_index);
66
}
67
EditorNode::get_singleton()->set_preview_locale(get_item_metadata(p_index));
68
}
69
70
void EditorTranslationPreviewMenu::_notification(int p_what) {
71
switch (p_what) {
72
case NOTIFICATION_READY: {
73
connect("about_to_popup", callable_mp(this, &EditorTranslationPreviewMenu::_prepare));
74
connect("index_pressed", callable_mp(this, &EditorTranslationPreviewMenu::_pressed));
75
} break;
76
}
77
}
78
79
EditorTranslationPreviewMenu::EditorTranslationPreviewMenu() {
80
set_hide_on_checkable_item_selection(false);
81
}
82
83