Add localization support in client

This commit is contained in:
Guillaume Meunier
2024-06-08 21:24:06 +02:00
parent 2483cb458f
commit 55ccb0d34b
17 changed files with 259 additions and 69 deletions
+7 -7
View File
@@ -140,7 +140,7 @@ scenes::lobby::lobby()
}
if (swapchain_format == vk::Format::eUndefined)
throw std::runtime_error("No supported swapchain format");
throw std::runtime_error(_("No supported swapchain format"));
spdlog::info("Using format {}", vk::to_string(swapchain_format));
}
@@ -175,10 +175,10 @@ std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service servic
auto protocol = service.txt.find("protocol");
if (protocol == service.txt.end())
throw std::runtime_error("Incompatible WiVRn server: no protocol field in TXT");
throw std::runtime_error(_("Incompatible WiVRn server: no protocol field in TXT"));
if (protocol->second != protocol_string)
throw std::runtime_error(fmt::format("Incompatible WiVRn server protocol (client: {}, server: {})", protocol_string, protocol->second));
throw std::runtime_error(fmt::format(_F("Incompatible WiVRn server protocol (client: {}, server: {})"), protocol_string, protocol->second));
}
// Only the automatically discovered servers already have their IP addresses available
@@ -193,7 +193,7 @@ std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service servic
if (int err = getaddrinfo(service.hostname.c_str(), nullptr, &hint, &addresses))
{
spdlog::error("Cannot resolve hostname {}: {}", service.hostname, gai_strerror(err));
throw std::runtime_error("Cannot resolve hostname: " + std::string(gai_strerror(err)));
throw std::runtime_error(fmt::format(_F("Cannot resolve hostname: {}"), _(gai_strerror(err))));
}
for (auto i = addresses; i; i = i->ai_next)
@@ -231,8 +231,8 @@ std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service servic
}
catch (std::exception & e)
{
std::string txt = fmt::format("Cannot connect to {} ({}): {}", service.hostname, address_string, e.what());
spdlog::warn(txt);
spdlog::warn("Cannot connect to {} ({}): {}", service.hostname, address_string, e.what());
std::string txt = fmt::format(_F("Cannot connect to {} ({}): {}"), service.hostname, address_string, e.what());
if (not error.empty())
error += "\n";
error += txt;
@@ -344,7 +344,7 @@ void scenes::lobby::connect(const configuration::server_data & data)
async_session = utils::async<std::unique_ptr<wivrn_session>, std::string>(
[](auto token, wivrn_discover::service service, bool manual) {
token.set_progress("Waiting for connection");
token.set_progress(_("Waiting for connection"));
return connect_to_session(service, manual);
},
data.service,
+38 -36
View File
@@ -80,9 +80,9 @@ void scenes::lobby::gui_connecting()
if (next_scene)
{
if (next_scene->current_state() == scenes::stream::state::stalled)
status = "Video stream interrupted";
status = _("Video stream interrupted");
else
status = "Waiting for video stream";
status = _("Waiting for video stream");
}
else if (async_session.valid())
status = async_session.get_progress();
@@ -97,14 +97,14 @@ void scenes::lobby::gui_connecting()
std::string button_label;
if (async_error)
button_label = "Close";
button_label = _("Close");
else
button_label = "Cancel";
button_label = _("Cancel");
ImGui::Dummy({1000, 1});
ImGui::PushFont(imgui_ctx->large_font);
CenterTextH(fmt::format("Connection to {}", server_name));
CenterTextH(fmt::format(_F("Connection to {}"), server_name));
ImGui::PopFont();
// ImGui::TextWrapped("%s", status.first.c_str());
@@ -132,7 +132,7 @@ void scenes::lobby::gui_add_server()
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Displayed name");
ImGui::Text("%s", _S("Displayed name"));
static char buf[100];
ImGui::TableNextColumn();
@@ -141,7 +141,7 @@ void scenes::lobby::gui_add_server()
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Host name");
ImGui::Text("%s", _S("Host name"));
static char buf2[100];
ImGui::TableNextColumn();
@@ -150,7 +150,7 @@ void scenes::lobby::gui_add_server()
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Port");
ImGui::Text("%s", _S("Port"));
static int port;
ImGui::TableNextColumn();
@@ -214,7 +214,7 @@ void scenes::lobby::gui_server_list()
{
ImGui::PushFont(imgui_ctx->large_font);
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 0.5));
CenterTextHV("Start a WiVRn server on your\nlocal network");
CenterTextHV(_("Start a WiVRn server on your\nlocal network"));
ImGui::PopStyleColor();
ImGui::PopFont();
}
@@ -243,7 +243,8 @@ void scenes::lobby::gui_server_list()
if (!data.manual)
{
ImGui::SetCursorPos(ImVec2(pos.x, pos.y + 50));
if (ImGui::Checkbox(("Autoconnect##" + cookie).c_str(), &data.autoconnect))
std::string label = _("Autoconnect") + "##" + cookie;
if (ImGui::Checkbox(label.c_str(), &data.autoconnect))
config.save();
vibrate_on_hover();
}
@@ -273,7 +274,8 @@ void scenes::lobby::gui_server_list()
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.2f, 0.4f, 0.3f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 0.5f, 0.2f, 1.00f));
}
if (ImGui::Button(("Connect##" + cookie).c_str(), button_size))
if (ImGui::Button((_("Connect") + "##" + cookie).c_str(), button_size))
{
connect(data);
ImGui::OpenPopup("connecting");
@@ -283,9 +285,9 @@ void scenes::lobby::gui_server_list()
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
{
if (!data.compatible)
ImGui::SetTooltip("Incompatible server version");
ImGui::SetTooltip("%s", _S("Incompatible server version"));
else if (!data.visible && !data.manual)
ImGui::SetTooltip("Server not available");
ImGui::SetTooltip("%s", _S("Server not available"));
}
ImGui::PopStyleColor(3);
@@ -299,7 +301,7 @@ void scenes::lobby::gui_server_list()
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
if (ImGui::Button(("Remove##" + cookie).c_str(), button_size))
if (ImGui::Button((_("Remove") + "##" + cookie).c_str(), button_size))
cookie_to_remove = cookie;
vibrate_on_hover();
@@ -343,7 +345,7 @@ void scenes::lobby::gui_settings()
float current = session.get_current_refresh_rate();
if (not refresh_rates.empty())
{
if (ImGui::BeginCombo("Refresh rate", fmt::format("{}", current).c_str()))
if (ImGui::BeginCombo(_S("Refresh rate"), fmt::format("{}", current).c_str()))
{
for (float rate: refresh_rates)
{
@@ -365,11 +367,11 @@ void scenes::lobby::gui_settings()
const auto current = config.resolution_scale;
const auto width = stream_view.recommendedImageRectWidth;
const auto height = stream_view.recommendedImageRectHeight;
if (ImGui::BeginCombo("Resolution scale", fmt::format("{} - {}x{} per eye", current, (int)(width * current), (int)(height * current)).c_str()))
if (ImGui::BeginCombo(_S("Resolution scale"), fmt::format(_F("{} - {}x{} per eye"), current, (int)(width * current), (int)(height * current)).c_str()))
{
for (float scale: available_scales)
{
if (ImGui::Selectable(fmt::format("{} - {}x{} per eye", scale, (int)(width * scale), (int)(height * scale)).c_str(), scale == current) and scale != current)
if (ImGui::Selectable(fmt::format(_F("{} - {}x{} per eye"), scale, (int)(width * scale), (int)(height * scale)).c_str(), scale == current) and scale != current)
{
config.resolution_scale = scale;
config.save();
@@ -380,7 +382,7 @@ void scenes::lobby::gui_settings()
vibrate_on_hover();
}
if (ImGui::Checkbox("Enable microphone", &config.microphone))
if (ImGui::Checkbox(_S("Enable microphone"), &config.microphone))
{
#ifdef __ANDROID__
if (config.microphone)
@@ -408,7 +410,7 @@ void scenes::lobby::gui_settings()
vibrate_on_hover();
ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough);
if (ImGui::Checkbox("Enable video passthrough in lobby", &config.passthrough_enabled))
if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled))
{
setup_passthrough();
config.save();
@@ -416,7 +418,7 @@ void scenes::lobby::gui_settings()
vibrate_on_hover();
ImGui::EndDisabled();
if (ImGui::Checkbox("Show performance metrics", &config.show_performance_metrics))
if (ImGui::Checkbox(_S("Show performance metrics"), &config.show_performance_metrics))
config.save();
vibrate_on_hover();
@@ -448,29 +450,29 @@ void scenes::lobby::gui_settings()
ImPlot::PushStyleColor(ImPlotCol_AxisBgActive, IM_COL32(0, 0, 0, 0));
ImPlot::PushStyleColor(ImPlotCol_AxisBgHovered, IM_COL32(0, 0, 0, 0));
if (ImPlot::BeginPlot("CPU time", plot_size, ImPlotFlags_CanvasOnly | ImPlotFlags_NoChild))
if (ImPlot::BeginPlot(_S("CPU time"), plot_size, ImPlotFlags_CanvasOnly | ImPlotFlags_NoChild))
{
auto col = ImPlot::GetColormapColor(0);
ImPlot::SetupAxes(nullptr, "CPU time", ImPlotAxisFlags_NoDecorations, 0);
ImPlot::SetupAxes(nullptr, _S("CPU time [ms]"), ImPlotAxisFlags_NoDecorations, 0);
ImPlot::SetupAxesLimits(0, cpu_time.size() - 1, min_v, max_v, ImGuiCond_Always);
ImPlot::SetNextLineStyle(col);
ImPlot::SetNextFillStyle(col, 0.25);
ImPlot::PlotLine("CPU time", cpu_time.data(), cpu_time.size(), 1, 0, ImPlotLineFlags_Shaded, offset);
ImPlot::PlotLine(_S("CPU time"), cpu_time.data(), cpu_time.size(), 1, 0, ImPlotLineFlags_Shaded, offset);
ImPlot::EndPlot();
}
ImGui::SameLine();
if (ImPlot::BeginPlot("GPU time", plot_size, ImPlotFlags_CanvasOnly | ImPlotFlags_NoChild))
if (ImPlot::BeginPlot(_S("GPU time"), plot_size, ImPlotFlags_CanvasOnly | ImPlotFlags_NoChild))
{
auto col = ImPlot::GetColormapColor(1);
ImPlot::SetupAxes(nullptr, "GPU time [ms]", ImPlotAxisFlags_NoDecorations, 0);
ImPlot::SetupAxes(nullptr, _S("GPU time [ms]"), ImPlotAxisFlags_NoDecorations, 0);
ImPlot::SetupAxesLimits(0, gpu_time.size() - 1, min_v, max_v, ImGuiCond_Always);
ImPlot::SetNextLineStyle(col);
ImPlot::SetNextFillStyle(col, 0.25);
ImPlot::PlotLine("GPU time", gpu_time.data(), gpu_time.size(), 1, 0, ImPlotLineFlags_Shaded, offset);
ImPlot::PlotLine(_S("GPU time"), gpu_time.data(), gpu_time.size(), 1, 0, ImPlotLineFlags_Shaded, offset);
ImPlot::EndPlot();
}
ImPlot::PopStyleColor(5);
@@ -491,7 +493,7 @@ void scenes::lobby::gui_about()
ImGui::Image(about_picture, {win_width / 2, win_width / 2});
}
static bool RadioButtonWithoutCheckBox(const char * label, bool active, ImVec2 size_arg)
static bool RadioButtonWithoutCheckBox(const std::string & label, bool active, ImVec2 size_arg)
{
ImGuiWindow * window = ImGui::GetCurrentWindow();
if (window->SkipItems)
@@ -499,8 +501,8 @@ static bool RadioButtonWithoutCheckBox(const char * label, bool active, ImVec2 s
ImGuiContext & g = *GImGui;
const ImGuiStyle & style = g.Style;
const ImGuiID id = window->GetID(label);
const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
const ImGuiID id = window->GetID(label.c_str());
const ImVec2 label_size = ImGui::CalcTextSize(label.c_str(), NULL, true);
const ImVec2 pos = window->DC.CursorPos;
@@ -526,14 +528,14 @@ static bool RadioButtonWithoutCheckBox(const char * label, bool active, ImVec2 s
ImGui::RenderFrame(bb.Min, bb.Max, ImGui::GetColorU32(col), true, style.FrameRounding);
ImVec2 TextAlign{0, 0.5f};
ImGui::RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, TextAlign, &bb);
ImGui::RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label.c_str(), NULL, &label_size, TextAlign, &bb);
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags);
IMGUI_TEST_ENGINE_ITEM_INFO(id, label.c_str(), g.LastItemData.StatusFlags);
return pressed;
}
template <typename T>
static bool RadioButtonWithoutCheckBox(const char * label, T * v, T v_button, ImVec2 size_arg)
static bool RadioButtonWithoutCheckBox(const std::string & label, T * v, T v_button, ImVec2 size_arg)
{
const bool pressed = RadioButtonWithoutCheckBox(label, *v == v_button, size_arg);
if (pressed)
@@ -629,17 +631,17 @@ XrCompositionLayerQuad scenes::lobby::draw_gui(XrTime predicted_display_time)
ImGui::BeginChild("Tabs", {TabWidth, ImGui::GetContentRegionMax().y - ImGui::GetWindowContentRegionMin().y});
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10));
RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " Server list", &current_tab, tab::server_list, {TabWidth, 0});
RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " " + _("Server list"), &current_tab, tab::server_list, {TabWidth, 0});
vibrate_on_hover();
RadioButtonWithoutCheckBox(ICON_FA_GEARS " Settings", &current_tab, tab::settings, {TabWidth, 0});
RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), &current_tab, tab::settings, {TabWidth, 0});
vibrate_on_hover();
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 2 * ImGui::GetCurrentContext()->FontSize - 4 * style.FramePadding.y - style.ItemSpacing.y - style.WindowPadding.y);
RadioButtonWithoutCheckBox(ICON_FA_CIRCLE_INFO " About", &current_tab, tab::about, {TabWidth, 0});
RadioButtonWithoutCheckBox(ICON_FA_CIRCLE_INFO " " + _("About"), &current_tab, tab::about, {TabWidth, 0});
vibrate_on_hover();
RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " Exit", &current_tab, tab::exit, {TabWidth, 0});
RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " " + _("Exit"), &current_tab, tab::exit, {TabWidth, 0});
vibrate_on_hover();
ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding
+2 -2
View File
@@ -185,10 +185,10 @@ private:
struct plot
{
const char * title;
std::string title;
struct subplot
{
const char * title;
std::string title;
float scenes::stream::global_metric::*data;
};
std::vector<subplot> subplots;
+15 -15
View File
@@ -141,13 +141,13 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
static const std::array plots = {
// clang-format off
plot("CPU time", {{"", &global_metric::cpu_time}}, "s"),
plot(_("CPU time"), {{"", &global_metric::cpu_time}}, "s"),
plot("GPU time", {{"Reproject", &global_metric::gpu_time},
{"Blit", &global_metric::gpu_barrier}}, "s"),
plot(_("GPU time"), {{_("Reproject"), &global_metric::gpu_time},
{_("Blit"), &global_metric::gpu_barrier}}, "s"),
plot("Network", {{"Download", &global_metric::bandwidth_rx},
{"Upload", &global_metric::bandwidth_tx}}, "bit/s"),
plot(("Network"), {{_("Download"), &global_metric::bandwidth_rx},
{_("Upload"), &global_metric::bandwidth_tx}}, "bit/s"),
// clang-format on
};
@@ -170,7 +170,7 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
int n = 0;
for (const auto & [title, subplots, unit]: plots)
{
if (ImPlot::BeginPlot(title, plot_size, ImPlotFlags_NoTitle | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText | ImPlotFlags_NoChild))
if (ImPlot::BeginPlot(title.c_str(), plot_size, ImPlotFlags_NoTitle | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText | ImPlotFlags_NoChild))
{
float min_v = 0;
float max_v = 0;
@@ -202,7 +202,7 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
.count = (int)global_metrics.size(),
.multiplier = multiplier,
};
ImPlot::PlotLineG(subtitle, getter, &gdata, global_metrics.size(), ImPlotLineFlags_Shaded);
ImPlot::PlotLineG(subtitle.c_str(), getter, &gdata, global_metrics.size(), ImPlotLineFlags_Shaded);
}
ImPlot::EndPlot();
}
@@ -213,7 +213,7 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
for (auto && [index, metrics]: utils::enumerate(decoder_metrics))
{
std::string title = "Decoder " + std::to_string(index);
std::string title = fmt::format(_F("Decoder {}"), std::to_string(index));
if (ImPlot::BeginPlot(title.c_str(), plot_size, ImPlotFlags_NoTitle | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText | ImPlotFlags_NoChild))
{
float min_v = 0;
@@ -225,8 +225,8 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
else
axis_scale[n] = 0.99 * axis_scale[n] + 0.01 * max_v;
const char * title_with_units = "Timings [ms]";
ImPlot::SetupAxes(nullptr, title_with_units, ImPlotAxisFlags_NoDecorations, 0);
std::string title_with_units = _("Timings [ms]");
ImPlot::SetupAxes(nullptr, title_with_units.c_str(), ImPlotAxisFlags_NoDecorations, 0);
ImPlot::SetupAxesLimits(0, metrics.size() - 1, min_v * 1e3f, axis_scale[n] * 1e3f, ImGuiCond_Always);
getter_data getter_send_begin{
@@ -286,11 +286,11 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
.multiplier = 1e3f};
// clang-format off
ImPlot::PlotShadedG("Send", getter, &getter_send_begin, getter, &getter_send_end, metrics.size());
ImPlot::PlotShadedG("Receive", getter, &getter_received_first_packet, getter, &getter_received_last_packet, metrics.size());
ImPlot::PlotShadedG("Decode", getter, &getter_sent_to_decoder, getter, &getter_received_from_decoder, metrics.size());
ImPlot::PlotLineG("Blitted", getter, &getter_blitted, metrics.size());
ImPlot::PlotLineG("Displayed", getter, &getter_displayed, metrics.size());
ImPlot::PlotShadedG(_S("Send"), getter, &getter_send_begin, getter, &getter_send_end, metrics.size());
ImPlot::PlotShadedG(_S("Receive"), getter, &getter_received_first_packet, getter, &getter_received_last_packet, metrics.size());
ImPlot::PlotShadedG(_S("Decode"), getter, &getter_sent_to_decoder, getter, &getter_received_from_decoder, metrics.size());
ImPlot::PlotLineG(_S("Blitted"), getter, &getter_blitted, metrics.size());
ImPlot::PlotLineG(_S("Displayed"), getter, &getter_displayed, metrics.size());
// clang-format on
ImPlot::EndPlot();