Browse Source

Add "Help > Language" menu item to select language setting.

tags/v2.6.1
Andrew Belt 5 months ago
parent
commit
e5c0819c3a
6 changed files with 56 additions and 9 deletions
  1. +1
    -1
      Makefile
  2. +1
    -0
      include/string.hpp
  3. +24
    -6
      src/app/MenuBar.cpp
  4. +14
    -1
      src/string.cpp
  5. +7
    -1
      translations/en.json
  6. +9
    -0
      translations/ja.json

+ 1
- 1
Makefile View File

@@ -172,7 +172,7 @@ else
endif
DIST_MD := $(wildcard *.md)
DIST_HTML := $(patsubst %.md, build/%.html, $(DIST_MD))
DIST_RES := res cacert.pem Core.json template.vcv LICENSE-GPLv3.txt $(DIST_HTML)
DIST_RES := res cacert.pem Core.json template.vcv LICENSE-GPLv3.txt $(DIST_HTML) translations
DIST_SDK_DIR := Rack-SDK
DIST_SDK = Rack-SDK-$(VERSION)-$(ARCH_NAME).zip



+ 1
- 0
include/string.hpp View File

@@ -133,6 +133,7 @@ struct Version {

std::string translate(const std::string& id);
std::string translate(const std::string& id, const std::string& language);
std::vector<std::string> getLanguages();
void init();




+ 24
- 6
src/app/MenuBar.cpp View File

@@ -982,6 +982,24 @@ struct HelpButton : MenuButton {
menu->cornerFlags = BND_CORNER_TOP;
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));

// Language
std::vector<std::string> languages = string::getLanguages();
std::vector<std::string> languageLabels;
for (const std::string& language : languages) {
languageLabels.push_back(string::translate("language", language));
}
menu->addChild(createIndexSubmenuItem("🌐 Language", languageLabels, [=]() {
auto it = std::find(languages.begin(), languages.end(), settings::language);
return it - languages.begin();
}, [=](size_t i) {
settings::language = get(languages, i, "en");
// Request restart
std::string msg = string::f("Rack must be restarted to change display language to %s. Restart Rack now?", string::translate("language").c_str());
if (osdialog_message(OSDIALOG_INFO, OSDIALOG_OK_CANCEL, msg.c_str())) {
APP->window->close();
}
}));

menu->addChild(createMenuItem("Tips", "", [=]() {
APP->scene->addChild(tipWindowCreate());
}));
@@ -1097,27 +1115,27 @@ struct MenuBar : widget::OpaqueWidget {
addChild(layout);

FileButton* fileButton = new FileButton;
fileButton->text = "File";
fileButton->text = string::translate("MenuBar.file");
layout->addChild(fileButton);

EditButton* editButton = new EditButton;
editButton->text = "Edit";
editButton->text = string::translate("MenuBar.edit");
layout->addChild(editButton);

ViewButton* viewButton = new ViewButton;
viewButton->text = "View";
viewButton->text = string::translate("MenuBar.view");
layout->addChild(viewButton);

EngineButton* engineButton = new EngineButton;
engineButton->text = "Engine";
engineButton->text = string::translate("MenuBar.engine");
layout->addChild(engineButton);

LibraryButton* libraryButton = new LibraryButton;
libraryButton->text = "Library";
libraryButton->text = string::translate("MenuBar.library");
layout->addChild(libraryButton);

HelpButton* helpButton = new HelpButton;
helpButton->text = "Help";
helpButton->text = string::translate("MenuBar.help");
layout->addChild(helpButton);

infoLabel = new InfoLabel;


+ 14
- 1
src/string.cpp View File

@@ -383,7 +383,7 @@ std::string translate(const std::string& id) {


std::string translate(const std::string& id, const std::string& language) {
auto it = translations.find(language);
const auto it = translations.find(language);
if (it == translations.end())
return "";

@@ -392,6 +392,19 @@ std::string translate(const std::string& id, const std::string& language) {
}


std::vector<std::string> getLanguages() {
std::vector<std::string> languages;
for (const auto& pair : translations) {
languages.push_back(pair.first);
}
// Sort by language name, by UTF-8 bytes
std::sort(languages.begin(), languages.end(), [](const std::string& a, const std::string& b) {
return translate("language", a) < translate("language", b);
});
return languages;
}


void init() {
loadTranslations();
}


+ 7
- 1
translations/en.json View File

@@ -1,3 +1,9 @@
{
"language": "English"
"language": "English",
"MenuBar.file": "File",
"MenuBar.edit": "Edit",
"MenuBar.view": "View",
"MenuBar.engine": "Engine",
"MenuBar.library": "Library",
"MenuBar.help": "Help"
}

+ 9
- 0
translations/ja.json View File

@@ -0,0 +1,9 @@
{
"language": "日本語",
"MenuBar.file": "ファイル",
"MenuBar.edit": "編集",
"MenuBar.view": "表示",
"MenuBar.engine": "エンジン",
"MenuBar.library": "ライブラリ",
"MenuBar.help": "ヘルプ"
}

Loading…
Cancel
Save