Skip to content

Commit

Permalink
en localization
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Oct 6, 2024
1 parent 6b308c3 commit f513a9e
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 32 deletions.
50 changes: 50 additions & 0 deletions res/localization/en.tml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
vocabulary{
settings_menu_title{
str{Settings}
}

sweep_speed_setting_title{
str{"Sweep speed:"}
}

mm_per_sec{
str{"mm/s"}
}

language_setting_title{
str{"Language:"}
}

spo2_settings_menu_title{
str{"SpO2 settings"}
}

waveform_color_setting_title{
str{"Color:"}
}

about_menu_title{
str{"About"}
}

about_menu:program_title{
str{"Bedside Patient Monitor DEMO program"}
}

about_menu:version{
str{"Version"}
}

about_menu:powered_by{
str{"Powered by"}
}

about_menu:copyright{
str{"Copyright"}
}

spo2_simulation{
str{"SpO2 %, SIMULATION"}
}

}
20 changes: 20 additions & 0 deletions res/localization/fi.tml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
vocabulary{
sliders{
str{liukusäädin}
}
image{
str{kuva}
}
selection_box{
str{"valintalaatikko"}
}
hello_world{
str{"Hei maailman!"}
}
some_checkbox{
str{"jokin valintaruutu"}
}
language{
str{"Kieli (Language):"}
}
}
20 changes: 20 additions & 0 deletions res/localization/ru.tml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
vocabulary{
sliders{
str{ползунки}
}
image{
str{изображение}
}
selection_box{
str{"выпадающее меню выбора"}
}
hello_world{
str{"Превед медвед!"}
}
some_checkbox{
str{"какая-то галочка"}
}
language{
str{"Язык (Language):"}
}
}
11 changes: 6 additions & 5 deletions src/bedsidemon/about_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "style.hpp"

using namespace std::string_literals;
using namespace std::string_view_literals;

using namespace ruis::length_literals;

Expand Down Expand Up @@ -54,7 +55,7 @@ std::vector<utki::shared_ref<ruis::widget>> make_contents(utki::shared_ref<ruis:
.font_size = font_size_program_title
}
},
U"Bedside Patient Monitor DEMO program"s
c.get().localization.get("about_menu:program_title")
),
m::gap(c,
{
Expand All @@ -65,7 +66,7 @@ std::vector<utki::shared_ref<ruis::widget>> make_contents(utki::shared_ref<ruis:
),
m::text(c,
{},
(U"Version: "s).append(utki::to_utf32(program_version))
std::u32string(c.get().localization.get("about_menu:version").string()).append(U": "sv).append(utki::to_utf32(program_version))
),
m::gap(c,
{
Expand All @@ -83,7 +84,7 @@ std::vector<utki::shared_ref<ruis::widget>> make_contents(utki::shared_ref<ruis:
.font_size = font_size
}
},
U"Powered by"s
c.get().localization.get("about_menu:powered_by")
),
m::text(c,
{
Expand Down Expand Up @@ -115,7 +116,7 @@ std::vector<utki::shared_ref<ruis::widget>> make_contents(utki::shared_ref<ruis:
),
m::text(c,
{},
U"Copyright (C) 2024 Gagistech Oy <[email protected]>"s
std::u32string(c.get().localization.get("about_menu:copyright").string()).append(U" © 2024 Gagistech Oy <[email protected]>"sv)
)
};
// clang-format on
Expand All @@ -132,7 +133,7 @@ about_menu::about_menu(utki::shared_ref<ruis::context> context) :
),
menu(
this->context, //
U"About"s,
this->context.get().localization.get("about_menu_title"),
make_contents(this->context)
)
{}
21 changes: 18 additions & 3 deletions src/bedsidemon/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ application::application(bool window, std::string_view res_path) :
ruisapp::window_params wp(r4::vector2<unsigned>(1024, 600));
return wp;
}()
)
),
res_path(papki::as_dir(res_path))
{
this->set_fullscreen(!window);

this->gui.init_standard_widgets(*this->get_res_file());

this->gui.context.get().loader.mount_res_pack(*this->get_res_file(papki::as_dir(res_path)));
this->gui.context.get().loader.mount_res_pack(*this->get_res_file(this->res_path));

this->load_language(this->settings_storage.get().cur_language_index);

auto c = make_root_widgets(this->gui.context);

Expand Down Expand Up @@ -97,7 +100,10 @@ application::application(bool window, std::string_view res_path) :

// add fake sensor
{
auto pw = utki::make_shared<spo2_parameter_window>(this->gui.context, U"SpO2 %, simulated");
auto pw = utki::make_shared<spo2_parameter_window>(
this->gui.context, //
this->gui.context.get().localization.get("spo2_simulation")
);
this->fake_spo2_sensor_v =
std::make_unique<fake_spo2_sensor>(pw, utki::cat(papki::as_dir(res_path), "spo2_measurements.tml"));

Expand Down Expand Up @@ -188,3 +194,12 @@ void bedsidemon::application::close_menu()
this->menu->on_close();
this->menu.reset();
}

void application::load_language(size_t index)
{
auto lng = settings::language_id_to_name_mapping.at(index).first;

this->gui.context.get().localization =
ruis::localization(tml::read(*this->get_res_file(utki::cat(this->res_path, "localization/", lng, ".tml"))));
this->gui.get_root().reload();
}
4 changes: 4 additions & 0 deletions src/bedsidemon/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class application : public ruisapp::application
public:
bedsidemon::settings_storage settings_storage;

const std::string res_path;

application(bool window, std::string_view res_path);

static application& inst()
Expand All @@ -55,6 +57,8 @@ class application : public ruisapp::application

void open_menu(utki::shared_ref<bedsidemon::menu> menu);
void close_menu();

void load_language(size_t index);
};

std::unique_ptr<application> create_application(std::string_view executable, utki::span<const char*> args);
Expand Down
2 changes: 1 addition & 1 deletion src/bedsidemon/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ constexpr auto size_close_button = 40_pp;

menu::menu(
utki::shared_ref<ruis::context> context, //
std::u32string title,
ruis::string title,
utki::span<const utki::shared_ref<ruis::widget>> contents
) :
// clang-format off
Expand Down
2 changes: 1 addition & 1 deletion src/bedsidemon/menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class menu : public ruis::nine_patch
public:
menu(
utki::shared_ref<ruis::context> context, //
std::u32string title,
ruis::string title,
utki::span<const utki::shared_ref<ruis::widget>> contents
);

Expand Down
35 changes: 24 additions & 11 deletions src/bedsidemon/settings_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class sweep_speed_selection_box_provider : public ruis::selection_box::provider
.font_size = style::font_size_setting
}
},
utki::to_utf32(utki::cat(speed_mm_per_sec, " mm/s"sv))
utki::to_utf32(utki::cat(speed_mm_per_sec, ' ')).append(c.get().localization.get("mm_per_sec").string())
)
}
);
Expand All @@ -95,7 +95,7 @@ class sweep_speed_selection_box_provider : public ruis::selection_box::provider
};
} // namespace

namespace{
namespace {
class language_selection_box_provider : public ruis::selection_box::provider
{
public:
Expand Down Expand Up @@ -140,7 +140,7 @@ class language_selection_box_provider : public ruis::selection_box::provider
// clang-format on
}
};
}
} // namespace

namespace {
std::vector<utki::shared_ref<ruis::widget>> make_menu_contents(utki::shared_ref<ruis::context> c)
Expand All @@ -163,13 +163,26 @@ std::vector<utki::shared_ref<ruis::widget>> make_menu_contents(utki::shared_ref<
constexpr const auto& lang_mapping = settings::language_id_to_name_mapping;

language_selection_box.get().selection_handler = [](ruis::selection_box& sb) {
auto& ss = settings_storage::inst();
auto s = ss.get();
auto sel = sb.get_selection();

// save the language to settings storage
{
auto& ss = settings_storage::inst();
auto s = ss.get();

ASSERT(sb.get_selection() < lang_mapping.size())
s.cur_language_index = sb.get_selection();
ASSERT(sel < lang_mapping.size())
s.cur_language_index = sel;

ss.set(s);
ss.set(s);
}

// reload the ui
{
sb.context.get().post_to_ui_thread([sel]() {
auto& app = bedsidemon::application::inst();
app.load_language(sel);
});
}
};

auto& ss = settings_storage::inst();
Expand All @@ -190,7 +203,7 @@ std::vector<utki::shared_ref<ruis::widget>> make_menu_contents(utki::shared_ref<
.font_size = style::font_size_setting
}
},
U"Sweep speed:"s
c.get().localization.get("sweep_speed_setting_title")
),
m::gap(c,
{
Expand Down Expand Up @@ -229,7 +242,7 @@ std::vector<utki::shared_ref<ruis::widget>> make_menu_contents(utki::shared_ref<
.font_size = style::font_size_setting
}
},
U"Language:"s
c.get().localization.get("language_setting_title")
),
m::gap(c,
{
Expand All @@ -254,7 +267,7 @@ settings_menu::settings_menu(utki::shared_ref<ruis::context> context) :
),
menu(
this->context, //
U"Settings"s,
this->context.get().localization.get("settings_menu_title"),
make_menu_contents(this->context)
)
{
Expand Down
13 changes: 5 additions & 8 deletions src/bedsidemon/spo2/spo2_parameter_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ constexpr auto font_size_secondary_value = 40_pp;

constexpr auto heart_size = 15_pp;

std::vector<utki::shared_ref<ruis::widget>> make_numeric_content(
utki::shared_ref<ruis::context> c,
std::u32string title
)
std::vector<utki::shared_ref<ruis::widget>> make_numeric_content(utki::shared_ref<ruis::context> c, ruis::string title)
{
// clang-format off
return {
Expand Down Expand Up @@ -133,7 +130,7 @@ std::vector<utki::shared_ref<ruis::widget>> make_numeric_content(
// clang-format on
}

std::vector<utki::shared_ref<ruis::widget>> make_widgets(utki::shared_ref<ruis::context> c, std::u32string title)
std::vector<utki::shared_ref<ruis::widget>> make_widgets(utki::shared_ref<ruis::context> c, ruis::string title)
{
// clang-format off
return {
Expand Down Expand Up @@ -204,7 +201,7 @@ std::vector<utki::shared_ref<ruis::widget>> make_widgets(utki::shared_ref<ruis::
.borders = {style::pw_padding}
}
},
make_numeric_content(c, title)
make_numeric_content(c, std::move(title))
)
}
),
Expand All @@ -227,7 +224,7 @@ std::vector<utki::shared_ref<ruis::widget>> make_widgets(utki::shared_ref<ruis::
}
} // namespace

spo2_parameter_window::spo2_parameter_window(utki::shared_ref<ruis::context> context, std::u32string title) :
spo2_parameter_window::spo2_parameter_window(utki::shared_ref<ruis::context> context, ruis::string title) :
ruis::widget( //
std::move(context),
{//
Expand All @@ -247,7 +244,7 @@ spo2_parameter_window::spo2_parameter_window(utki::shared_ref<ruis::context> con
{//
.layout = ruis::layout::row
}},
make_widgets(this->context, title)
make_widgets(this->context, std::move(title))
),
spo2_value(this->get_widget_as<ruis::text>("spo2_value")),
bpm_value(this->get_widget_as<ruis::text>("bpm_value")),
Expand Down
2 changes: 1 addition & 1 deletion src/bedsidemon/spo2/spo2_parameter_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class spo2_parameter_window :
std::shared_ptr<spo2_parameter_window_menu> pw_menu;

public:
spo2_parameter_window(utki::shared_ref<ruis::context> context, std::u32string title = std::u32string(U"SpO2 %"));
spo2_parameter_window(utki::shared_ref<ruis::context> context, ruis::string title = std::u32string(U"SpO2 %"));
~spo2_parameter_window() override;

spo2_parameter_window(const spo2_parameter_window&) = delete;
Expand Down
4 changes: 2 additions & 2 deletions src/bedsidemon/spo2/spo2_parameter_window_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ std::vector<utki::shared_ref<ruis::widget>> make_menu_contents(utki::shared_ref<
.font_size = style::font_size_setting
}
},
U"Color:"s
c.get().localization.get("waveform_color_setting_title")
),
m::gap(c,
{
Expand Down Expand Up @@ -138,7 +138,7 @@ spo2_parameter_window_menu::spo2_parameter_window_menu(
),
menu(
this->context, //
U"SpO2"s,
this->context.get().localization.get("spo2_settings_menu_title"),
make_menu_contents(this->context)
),
spo2_pw(std::move(spo2_pw))
Expand Down

0 comments on commit f513a9e

Please sign in to comment.