feature: localization (#32)

* build: add nlohmann/json library

* build(deps): add harfbuzz dependency

* feat(cmake): add guard to reject macOS builds

* feat(font): add HarfBuzz shaping and replace font with unifont

* feat(localization): add i18n support with en_US and zh_CN translations

Implement Localization class to load JSON translation files. Replace hardcoded strings in UI with translation keys and update sliders/combo buttons to use dynamic text.

* feat(localization): detect system locale for language default

* feat(settings): add language selection option with restart notification

* fix: use vckpg to add freetype on windows
This commit is contained in:
zhenyan121
2026-07-16 17:11:53 +08:00
committed by GitHub
parent cc2df5e4ec
commit d62b310a21
33 changed files with 26143 additions and 137 deletions

View File

@@ -1,6 +1,7 @@
#include "Cubed/ui/host_game_ui.hpp"
#include "Cubed/app.hpp"
#include "Cubed/localization.hpp"
#include "Cubed/scene/host_game_scene.hpp"
#include "Cubed/scene/scene_manager.hpp"
#include "Cubed/ui/button.hpp"
@@ -32,7 +33,7 @@ void HostGameUI::init() {
param.host_game = true;
{
auto& label = layout.add_child<Label>();
label.set_text("Create A New World");
label.set_text(tr("hostgame.create_a_new_world"));
label.set_scale(0.7f);
}
{
@@ -45,7 +46,7 @@ void HostGameUI::init() {
}
{
auto& text_seed = layout.add_child<TextField>();
text_seed.set_show_text("WorldSeed");
text_seed.set_show_text(tr("hostgame.world_seed"));
text_seed.set_app(&m_scene.scene_manager().app());
text_seed.set_default_image(texture_manager);
text_seed.set_on_finish([this, &text_seed]() {
@@ -67,7 +68,7 @@ void HostGameUI::init() {
{
auto& text_port = layout.add_child<TextField>();
text_port.set_default_image(texture_manager);
text_port.set_show_text("Port: 25530");
text_port.set_show_text(tr("hostgame.port"));
text_port.set_app(&m_scene.scene_manager().app());
text_port.set_on_finish([this, &text_port]() {
int port = 25530;
@@ -93,7 +94,7 @@ void HostGameUI::init() {
{
auto& button = layout.add_child<Button>();
button.set_default_image(texture_manager);
button.set_text("Start Game");
button.set_text(tr("hostgame.create_world"));
button.set_clicked([this, &button]() {
button.set_enable(false);
m_scene.scene_manager().request_change(SceneType::WORLD);
@@ -102,7 +103,7 @@ void HostGameUI::init() {
{
auto& button = layout.add_child<Button>();
button.set_default_image(texture_manager);
button.set_text("Return");
button.set_text(tr("button.return"));
button.set_clicked([this, &button]() {
button.set_enable(false);
m_scene.scene_manager().request_pop();