context-based translation test

This commit is contained in:
MihailRis 2023-12-12 22:59:21 +03:00
parent 4e6818fb7f
commit e97eb441d5
5 changed files with 48 additions and 54 deletions

View File

@ -1,26 +1,7 @@
# Menu # Menu
menu.new-world=New World
menu.quit=Quit
menu.create-world=Create World
menu.save-and-quit=Save and Quit to Menu
menu.missing-content=Missing Content! menu.missing-content=Missing Content!
menu.controls=Controls
menu.back-to-menu=Back to Main Menu
menu.settings=Settings
world.seed=Seed
world.name=World Name
world.create=Create World
world.convert-request=Content indices have changed! Convert world files? world.convert-request=Content indices have changed! Convert world files?
# Settings
chunks.load-distance=Load Distance
chunks.load-speed=Load Speed
graphics.fog-curve=Fog Curve
graphics.backlight=Backlight
display.vsync=V-Sync
camera.fov=FOV
mouse.sensitivity=Mouse Sensitivity
# Bindings # Bindings
movement.forward=Forward movement.forward=Forward
movement.back=Back movement.back=Back

View File

@ -7,27 +7,29 @@ Back=Назад
Continue=Продолжить Continue=Продолжить
# Меню # Меню
menu.new-world=Новый Мир menu.New World=Новый Мир
menu.quit=Выход menu.Quit=Выход
menu.continue=Продолжить menu.Continue=Продолжить
menu.save-and-quit=Сохранить и Выйти в Меню menu.Save and Quit to Menu=Сохранить и Выйти в Меню
menu.missing-content=Отсутствует Контент! menu.missing-content=Отсутствует Контент!
menu.controls=Управление menu.Controls=Управление
menu.back-to-menu=Вернуться в Меню menu.Back to Main Menu=Вернуться в Меню
menu.settings=Настройки menu.Settings=Настройки
world.seed=Зерно world.Seed=Зерно
world.name=Название world.Name=Название
world.create=Создать Мир world.Create World=Создать Мир
world.convert-request=Есть изменения в индексах! Конвертировать мир? world.convert-request=Есть изменения в индексах! Конвертировать мир?
# Настройки # Настройки
chunks.load-distance=Дистанция Загрузки settings.Load Distance=Дистанция Загрузки
chunks.load-speed=Скорость Загрузки settings.Load Speed=Скорость Загрузки
graphics.fog-curve=Кривая Тумана settings.Fog Curve=Кривая Тумана
graphics.backlight=Подсветка settings.Backlight=Подсветка
display.vsync=V-Sync settings.V-Sync=Вертикальная Синхронизация
camera.fov=Поле Зрения
mouse.sensitivity=Чувствительность Мыши FOV=Поле Зрения
settings.Mouse Sensitivity=Чувствительность Мыши
# Управление # Управление
movement.forward=Вперёд movement.forward=Вперёд

View File

@ -131,3 +131,12 @@ void langs::setup(const path& resdir,
const wstring& langs::get(const wstring& key) { const wstring& langs::get(const wstring& key) {
return current->get(key); return current->get(key);
} }
const wstring& langs::get(const wstring& key, const wstring& context) {
wstring ctxkey = context + L"." + key;
const wstring& text = current->get(ctxkey);
if (&ctxkey != &text) {
return text;
}
return current->get(key);
}

View File

@ -56,6 +56,8 @@ namespace langs {
std::vector<const ContentPack*>& packs); std::vector<const ContentPack*>& packs);
extern const std::wstring& get(const std::wstring& key); extern const std::wstring& get(const std::wstring& key);
extern const std::wstring& get(const std::wstring& key,
const std::wstring& context);
extern void setup(const std::filesystem::path& resdir, extern void setup(const std::filesystem::path& resdir,
const std::string& locale, const std::string& locale,

View File

@ -68,7 +68,7 @@ void show_content_missing(GUI* gui, const Content* content, ContentLUT* lut) {
subpanel->maxLength(400); subpanel->maxLength(400);
panel->add(subpanel); panel->add(subpanel);
panel->add((new Button(langs::get(L"menu.back-to-menu"), vec4(8.0f)))->listenAction([=](GUI*){ panel->add((new Button(langs::get(L"Back to Main Menu", L"menu"), vec4(8.0f)))->listenAction([=](GUI*){
menu->back(); menu->back();
})); }));
panel->refresh(); panel->refresh();
@ -97,7 +97,7 @@ Panel* create_main_menu_panel(Engine* engine, PagesControl* menu) {
Panel* panel = new Panel(vec2(400, 200), vec4(5.0f), 1.0f); Panel* panel = new Panel(vec2(400, 200), vec4(5.0f), 1.0f);
panel->color(vec4(0.0f)); panel->color(vec4(0.0f));
panel->add(guiutil::gotoButton(langs::get(L"menu.new-world"), "new-world", menu)); panel->add(guiutil::gotoButton(langs::get(L"New World", L"menu"), "new-world", menu));
Panel* worldsPanel = new Panel(vec2(390, 200), vec4(5.0f)); Panel* worldsPanel = new Panel(vec2(390, 200), vec4(5.0f));
worldsPanel->color(vec4(1.0f, 1.0f, 1.0f, 0.07f)); worldsPanel->color(vec4(1.0f, 1.0f, 1.0f, 0.07f));
@ -135,8 +135,8 @@ Panel* create_main_menu_panel(Engine* engine, PagesControl* menu) {
} }
} }
panel->add(worldsPanel); panel->add(worldsPanel);
panel->add(guiutil::gotoButton(langs::get(L"menu.settings"), "settings", menu)); panel->add(guiutil::gotoButton(langs::get(L"Settings", L"menu"), "settings", menu));
panel->add((new Button(langs::get(L"menu.quit"), vec4(10.f)))->listenAction([](GUI* gui) { panel->add((new Button(langs::get(L"Quit", L"menu"), vec4(10.f)))->listenAction([](GUI* gui) {
Window::setShouldClose(true); Window::setShouldClose(true);
})); }));
panel->refresh(); panel->refresh();
@ -149,7 +149,7 @@ Panel* create_new_world_panel(Engine* engine, PagesControl* menu) {
TextBox* worldNameInput; TextBox* worldNameInput;
{ {
Label* label = new Label(langs::get(L"world.name")); Label* label = new Label(langs::get(L"Name", L"world"));
panel->add(label); panel->add(label);
TextBox* input = new TextBox(L"New World", vec4(6.0f)); TextBox* input = new TextBox(L"New World", vec4(6.0f));
@ -159,7 +159,7 @@ Panel* create_new_world_panel(Engine* engine, PagesControl* menu) {
TextBox* seedInput; TextBox* seedInput;
{ {
Label* label = new Label(langs::get(L"world.seed")); Label* label = new Label(langs::get(L"Seed", L"world"));
panel->add(shared_ptr<UINode>(label)); panel->add(shared_ptr<UINode>(label));
uint64_t randseed = rand() ^ (rand() << 8) ^ uint64_t randseed = rand() ^ (rand() << 8) ^
@ -173,7 +173,7 @@ Panel* create_new_world_panel(Engine* engine, PagesControl* menu) {
} }
{ {
Button* button = new Button(langs::get(L"world.create"), vec4(10.0f)); Button* button = new Button(langs::get(L"Create World", L"world"), vec4(10.0f));
button->margin(vec4(1, 20, 1, 1)); button->margin(vec4(1, 20, 1, 1));
vec4 basecolor = worldNameInput->color(); vec4 basecolor = worldNameInput->color();
button->listenAction([=](GUI*) { button->listenAction([=](GUI*) {
@ -239,7 +239,7 @@ Panel* create_controls_panel(Engine* engine, PagesControl* menu) {
std::wstringstream ss; std::wstringstream ss;
ss << std::fixed << std::setprecision(1); ss << std::fixed << std::setprecision(1);
ss << engine->getSettings().camera.sensitivity; ss << engine->getSettings().camera.sensitivity;
return langs::get(L"mouse.sensitivity")+L": "+ss.str(); return langs::get(L"Mouse Sensitivity", L"settings")+L": "+ss.str();
})); }));
TrackBar* trackbar = new TrackBar(0.1, 10.0, 2.0, 0.1, 4); TrackBar* trackbar = new TrackBar(0.1, 10.0, 2.0, 0.1, 4);
@ -282,7 +282,7 @@ Panel* create_settings_panel(Engine* engine, PagesControl* menu) {
/* Load Distance setting track bar */{ /* Load Distance setting track bar */{
panel->add((new Label(L""))->textSupplier([=]() { panel->add((new Label(L""))->textSupplier([=]() {
return langs::get(L"chunks.load-distance")+L": " + return langs::get(L"Load Distance", L"settings")+L": " +
std::to_wstring(engine->getSettings().chunks.loadDistance); std::to_wstring(engine->getSettings().chunks.loadDistance);
})); }));
@ -298,7 +298,7 @@ Panel* create_settings_panel(Engine* engine, PagesControl* menu) {
/* Load Speed setting track bar */{ /* Load Speed setting track bar */{
panel->add((new Label(L""))->textSupplier([=]() { panel->add((new Label(L""))->textSupplier([=]() {
return langs::get(L"chunks.load-speed")+L": " + return langs::get(L"Load Speed", L"settings")+L": " +
std::to_wstring(engine->getSettings().chunks.loadSpeed); std::to_wstring(engine->getSettings().chunks.loadSpeed);
})); }));
@ -317,7 +317,7 @@ Panel* create_settings_panel(Engine* engine, PagesControl* menu) {
std::wstringstream ss; std::wstringstream ss;
ss << std::fixed << std::setprecision(1); ss << std::fixed << std::setprecision(1);
ss << engine->getSettings().graphics.fogCurve; ss << engine->getSettings().graphics.fogCurve;
return langs::get(L"graphics.fog-curve")+L": " + ss.str(); return langs::get(L"Fog Curve", L"settings")+L": " + ss.str();
})); }));
TrackBar* trackbar = new TrackBar(1.0, 6.0, 1.0, 0.1, 2); TrackBar* trackbar = new TrackBar(1.0, 6.0, 1.0, 0.1, 2);
@ -333,7 +333,7 @@ Panel* create_settings_panel(Engine* engine, PagesControl* menu) {
/* Fov setting track bar */{ /* Fov setting track bar */{
panel->add((new Label(L""))->textSupplier([=]() { panel->add((new Label(L""))->textSupplier([=]() {
int fov = (int)engine->getSettings().camera.fov; int fov = (int)engine->getSettings().camera.fov;
return langs::get(L"camera.fov")+L": "+std::to_wstring(fov)+L"°"; return langs::get(L"FOV", L"settings")+L": "+std::to_wstring(fov)+L"°";
})); }));
TrackBar* trackbar = new TrackBar(30.0, 120.0, 90, 1, 4); TrackBar* trackbar = new TrackBar(30.0, 120.0, 90, 1, 4);
@ -360,7 +360,7 @@ Panel* create_settings_panel(Engine* engine, PagesControl* menu) {
engine->getSettings().display.swapInterval = checked; engine->getSettings().display.swapInterval = checked;
}); });
checkpanel->add(checkbox); checkpanel->add(checkbox);
checkpanel->add(new Label(langs::get(L"display.vsync"))); checkpanel->add(new Label(langs::get(L"V-Sync", L"settings")));
panel->add(checkpanel); panel->add(checkpanel);
} }
@ -379,12 +379,12 @@ Panel* create_settings_panel(Engine* engine, PagesControl* menu) {
engine->getSettings().graphics.backlight = checked; engine->getSettings().graphics.backlight = checked;
}); });
checkpanel->add(checkbox); checkpanel->add(checkbox);
checkpanel->add(new Label(langs::get(L"graphics.backlight"))); checkpanel->add(new Label(langs::get(L"Backlight", L"settings")));
panel->add(checkpanel); panel->add(checkpanel);
} }
panel->add(guiutil::gotoButton(langs::get(L"menu.controls"), "controls", menu)); panel->add(guiutil::gotoButton(langs::get(L"Controls", L"menu"), "controls", menu));
panel->add(guiutil::backButton(menu)); panel->add(guiutil::backButton(menu));
panel->refresh(); panel->refresh();
return panel; return panel;
@ -394,15 +394,15 @@ Panel* create_pause_panel(Engine* engine, PagesControl* menu) {
Panel* panel = new Panel(vec2(400, 200)); Panel* panel = new Panel(vec2(400, 200));
panel->color(vec4(0.0f)); panel->color(vec4(0.0f));
{ {
Button* button = new Button(langs::get(L"Continue"), vec4(10.0f)); Button* button = new Button(langs::get(L"Continue", L"menu"), vec4(10.0f));
button->listenAction([=](GUI*){ button->listenAction([=](GUI*){
menu->reset(); menu->reset();
}); });
panel->add(shared_ptr<UINode>(button)); panel->add(shared_ptr<UINode>(button));
} }
panel->add(guiutil::gotoButton(langs::get(L"Settings"), "settings", menu)); panel->add(guiutil::gotoButton(langs::get(L"Settings", L"menu"), "settings", menu));
{ {
Button* button = new Button(langs::get(L"menu.save-and-quit"), vec4(10.f)); Button* button = new Button(langs::get(L"Save and Quit to Menu", L"menu"), vec4(10.f));
button->listenAction([engine](GUI*){ button->listenAction([engine](GUI*){
engine->setScreen(shared_ptr<Screen>(new MenuScreen(engine))); engine->setScreen(shared_ptr<Screen>(new MenuScreen(engine)));
}); });