mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
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:
@@ -1,5 +1,6 @@
|
||||
#include "Cubed/ui/slider.hpp"
|
||||
|
||||
#include "Cubed/localization.hpp"
|
||||
#include "Cubed/tools/cubed_assert.hpp"
|
||||
#include "Cubed/tools/log.hpp"
|
||||
|
||||
@@ -84,8 +85,10 @@ Slider& Slider::set_height(float h) {
|
||||
update_text_scale();
|
||||
return *this;
|
||||
}
|
||||
Slider& Slider::set_text(const std::string& text) {
|
||||
m_text = text;
|
||||
Slider& Slider::set_slider_text(const std::string& key,
|
||||
const std::string& variable) {
|
||||
m_key = key;
|
||||
m_variable = variable;
|
||||
return *this;
|
||||
}
|
||||
Slider& Slider::set_track_image(const std::string& path,
|
||||
@@ -164,7 +167,7 @@ void Slider::on_update(float dt) {
|
||||
}
|
||||
float range = m_max - m_min;
|
||||
if (range <= 0.0f) {
|
||||
Logger::error("Slider {} Range {} is <= 0.0f", m_text, range);
|
||||
Logger::error("Slider {} Range {} is <= 0.0f", m_key, range);
|
||||
ASSERT(false);
|
||||
return;
|
||||
}
|
||||
@@ -184,11 +187,12 @@ void Slider::on_update(float dt) {
|
||||
m_thumb->set_offset({offset, 0});
|
||||
if (m_label) {
|
||||
if (m_type == ValueType::FLOAT && m_float_value) {
|
||||
m_label->set_text(
|
||||
std::format("{}: {:.2f}", m_text, *m_float_value));
|
||||
|
||||
m_label->set_text(tr(
|
||||
m_key, arg(m_variable, std::format("{:.2f}", *m_float_value))));
|
||||
}
|
||||
if (m_type == ValueType::INT && m_int_value) {
|
||||
m_label->set_text(std::format("{}: {}", m_text, *m_int_value));
|
||||
m_label->set_text(tr(m_key, arg(m_variable, *m_int_value)));
|
||||
}
|
||||
}
|
||||
if (m_track) {
|
||||
|
||||
Reference in New Issue
Block a user