diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 489ab5a0..4bbd8fd0 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -91,7 +91,7 @@ jobs: - name: Install dependencies run: > - sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev libxcb-glx0-dev + sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev libxcb-glx0-dev gettext - name: Configure CMake run: > @@ -163,7 +163,7 @@ jobs: - name: Install dependencies run: > - sudo apt-get update && sudo apt-get install glslang-tools librsvg2-bin + sudo apt-get update && sudo apt-get install glslang-tools librsvg2-bin gettext - name: Check for Secret availability id: secret-check diff --git a/.github/workflows/Locales.yml b/.github/workflows/Locales.yml new file mode 100644 index 00000000..d6ae87af --- /dev/null +++ b/.github/workflows/Locales.yml @@ -0,0 +1,14 @@ +name: Locales +on: [push, pull_request] +jobs: + locale-check: + name: Locale check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install gettext + + - name: Check that .po files are up to date + run: tools/check_messages.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ab07683..1c7165da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,15 +58,15 @@ include(VulkanVersion) if (WIVRN_USE_SYSTEM_BOOST STREQUAL "AUTO") if(WIVRN_BUILD_DISSECTOR) - find_package(Boost 1.84.0) + find_package(Boost 1.84.0 COMPONENTS locale) else() - find_package(Boost 1.75.0) + find_package(Boost 1.75.0 COMPONENTS locale) endif() elseif(WIVRN_USE_SYSTEM_BOOST STREQUAL "ON") if(WIVRN_BUILD_DISSECTOR) - find_package(Boost 1.84.0 REQUIRED) + find_package(Boost 1.84.0 REQUIRED COMPONENTS locale) else() - find_package(Boost 1.75.0 REQUIRED) + find_package(Boost 1.75.0 REQUIRED COMPONENTS locale) endif() endif() @@ -164,6 +164,7 @@ endif() # Common dependencies FetchContent_Declare(boostpfr URL https://github.com/boostorg/pfr/archive/refs/tags/2.2.0.tar.gz) +FetchContent_Declare(boost URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz) # Client dependencies FetchContent_Declare(simdjson URL https://github.com/simdjson/simdjson/archive/refs/tags/v3.9.3.tar.gz) FetchContent_Declare(fastgltf URL https://github.com/spnda/fastgltf/archive/refs/tags/v0.7.1.tar.gz) diff --git a/README.md b/README.md index 4661a41d..2745fc67 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ See [configuration](docs/configuration.md) for configurable items. WiVRn uses the following software: - [ambientCG](https://ambientcg.com/) - [Avahi](https://www.avahi.org/) +- [Boost.Locale](https://github.com/boostorg/locale) - [Boost.PFR](https://github.com/boostorg/pfr) - [Dear ImGui](https://github.com/ocornut/imgui) - [fastgltf](https://github.com/spnda/fastgltf) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 7f61e0e9..323208cb 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -9,6 +9,10 @@ set(FASTGLTF_COMPILE_AS_CPP20 ON) FetchContent_MakeAvailable(simdjson spdlog glm fastgltf imgui stb libktx implot) +if (NOT BOOST_FOUND) + FetchContent_MakeAvailable(boost) +endif() + include(FreetypeHarfbuzz) include(CompileGLSL) @@ -123,7 +127,7 @@ file(GLOB_RECURSE VULKAN_SHADERS CONFIGURE_DEPENDS "*.glsl") target_sources(wivrn PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS}) wivrn_compile_glsl(wivrn ${VULKAN_SHADERS}) -target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm fastgltf FreetypeHarfbuzz stb ktx_read) +target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm fastgltf FreetypeHarfbuzz stb ktx_read Boost::locale) target_compile_definitions(wivrn PRIVATE -DXR_USE_GRAPHICS_API_VULKAN) target_compile_definitions(wivrn PRIVATE -DVMA_STATS_STRING_ENABLED=0) target_compile_options(wivrn PRIVATE -fdiagnostics-color -Wall -Wextra -pedantic) # -Werror @@ -171,3 +175,28 @@ if(USE_ANDROID_VALIDATION_LAYER) target_link_libraries(wivrn vvl1 vvl2) # Hack to get gradle to package the validation layer in the APK endif() +find_program(GETTEXT_MSGFMT_COMMAND msgfmt REQUIRED) + +set(MO_FILES) +file(GLOB PO_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/locale/*") +foreach(PO_DIR IN LISTS PO_DIRS) + cmake_path(GET PO_DIR FILENAME LANG) + + if(ANDROID) + set(MO_DIR ${CMAKE_ANDROID_ASSETS_DIRECTORIES}/locale/${LANG}/LC_MESSAGES) + else() + set(MO_DIR ${CMAKE_CURRENT_BINARY_DIR}/locale/${LANG}/LC_MESSAGES) + endif() + set(MO_FILE ${MO_DIR}/wivrn.mo) + set(PO_FILE ${PO_DIR}/wivrn.po) + + add_custom_command(OUTPUT ${MO_FILE} + COMMAND ${CMAKE_COMMAND} -E make_directory ${MO_DIR} + COMMAND ${GETTEXT_MSGFMT_COMMAND} ${PO_FILE} -o ${MO_FILE} + DEPENDS ${PO_FILE}) + set(MO_FILES ${MO_FILES} ${MO_FILE}) + +endforeach() + +add_custom_target(translations ALL DEPENDS ${MO_FILES}) +add_dependencies(wivrn translations) diff --git a/client/application.cpp b/client/application.cpp index 101bc75a..59628eec 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -18,6 +18,7 @@ */ #include "application.h" +#include "asset.h" #include "openxr/openxr.h" #include "scene.h" #include "spdlog/common.h" @@ -31,6 +32,7 @@ #include "xr/check.h" #include "xr/xr.h" #include +#include #include #include #include @@ -836,6 +838,53 @@ void application::initialize() initialize_actions(); interaction_profile_changed(); + + gen.add_messages_domain("wivrn"); + std::locale loc = gen(""); + +#ifdef __ANDROID__ + jni::klass java_util_Locale("java/util/Locale"); + auto default_locale = java_util_Locale.call>("getDefault"); + + // if (auto language = default_locale.call("toString")) + if (auto language = default_locale.call("getLanguage")) + messages_info.language = language; + + if (auto country = default_locale.call("getCountry")) + messages_info.country = country; + + messages_info.encoding = "UTF-8"; + +#else + auto & facet = std::use_facet(loc); + messages_info.language = facet.language(); + messages_info.country = facet.country(); + messages_info.encoding = facet.encoding(); +#endif + + spdlog::info("Current locale: language {}, country {}, encoding {}", messages_info.language, messages_info.country, messages_info.encoding); + + messages_info.paths.push_back("locale"); + + messages_info.domains.push_back(boost::locale::gnu_gettext::messages_info::domain("wivrn")); + messages_info.callback = [](const std::string & file_name, const std::string & encoding) { + std::vector buffer; + try + { + asset file(file_name); + buffer.resize(file.size()); + memcpy(buffer.data(), file.data(), file.size()); + } + catch (...) + { + } + + return buffer; + }; + + loc = std::locale(loc, boost::locale::gnu_gettext::create_messages_facet(messages_info)); + + std::locale::global(loc); } std::pair application::get_action(const std::string & requested_name) diff --git a/client/application.h b/client/application.h index 5853f102..4763654c 100644 --- a/client/application.h +++ b/client/application.h @@ -29,6 +29,9 @@ #include "vk/vk_allocator.h" #include "xr/xr.h" #include +#include +#include +#include #include #include #include @@ -43,6 +46,10 @@ #include #include +#define _(x) boost::locale::gettext(x) +#define _F(x) fmt::runtime(boost::locale::gettext(x)) +#define _S(x) boost::locale::gettext(x).c_str() + class scene; struct application_info @@ -137,6 +144,9 @@ class application : public singleton std::optional config; + boost::locale::generator gen; + boost::locale::gnu_gettext::messages_info messages_info; + void loop(); std::mutex debug_report_mutex; @@ -414,4 +424,9 @@ public: assert(instance().config); return *instance().config; } + + static boost::locale::gnu_gettext::messages_info & get_messages_info() + { + return instance().messages_info; + } }; diff --git a/client/jnipp.h b/client/jnipp.h index 6416388c..91ee0802 100644 --- a/client/jnipp.h +++ b/client/jnipp.h @@ -76,6 +76,7 @@ struct Void return "V"; } constexpr static const auto call_method = &_JNIEnv::CallVoidMethod; + constexpr static const auto call_static_method = &_JNIEnv::CallStaticVoidMethod; }; namespace details @@ -166,6 +167,21 @@ struct klass jfieldID id = env.GetStaticFieldID(*this, name.c_str(), T::type().c_str()); return T((env.*T::static_field)(*this, id)); } + + template + auto call(const char * method, Args &&... args) + { + using R1 = details::type_map_t; + auto & env = jni_thread::env(); + std::string signature = "(" + details::build_type(args...) + ")" + R1::type(); + auto method_id = env.GetStaticMethodID(self.get(), method, signature.c_str()); + assert(method_id); + auto handles = details::handle(std::forward(args)...); + return R(std::apply([&](auto &... t) { + return (env.*R1::call_static_method)(*this, method_id, t...); + }, + handles)); + } }; struct Bool @@ -175,6 +191,7 @@ struct Bool return "Z"; } constexpr static const auto call_method = &_JNIEnv::CallBooleanMethod; + constexpr static const auto call_static_method = &_JNIEnv::CallStaticBooleanMethod; bool value; @@ -193,6 +210,7 @@ struct Int { constexpr static auto static_field = &_JNIEnv::GetStaticIntField; constexpr static const auto call_method = &_JNIEnv::CallIntMethod; + constexpr static const auto call_static_method = &_JNIEnv::CallStaticIntMethod; static std::string type() { @@ -222,6 +240,7 @@ struct object std::unique_ptr, details::deleter> self; constexpr static const auto call_method = &_JNIEnv::CallObjectMethod; + constexpr static const auto call_static_method = &_JNIEnv::CallStaticObjectMethod; object(jobject o) { diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index ef6c772b..cf87aa1b 100644 --- a/client/render/imgui_impl.cpp +++ b/client/render/imgui_impl.cpp @@ -29,11 +29,13 @@ #include "vulkan/vulkan_to_string.hpp" #include #include +#include #include #include #include #include #include +#include #include #include @@ -104,6 +106,11 @@ static void check_vk_result(VkResult result) } } +const std::map> glyph_ranges_per_language = + { + {"fr", {0x0020, 0x017f, 0}} // Basic Latin + Latin Supplement + Latin Extended-A +}; + std::optional> imgui_context::ray_plane_intersection(const imgui_context::controller_state & in) const { if (!in.active) @@ -266,9 +273,16 @@ imgui_context::imgui_context(vk::raii::PhysicalDevice physical_device, vk::raii: asset font_awesome_regular("Font Awesome 6 Free-Regular-400.otf"); asset font_awesome_solid("Font Awesome 6 Free-Solid-900.otf"); { + auto language = application::get_messages_info().language; + + const ImWchar * range = io.Fonts->GetGlyphRangesDefault(); + + if (auto it = glyph_ranges_per_language.find(language); it != glyph_ranges_per_language.end()) + range = it->second.data(); + ImFontConfig config; config.FontDataOwnedByAtlas = false; - io.Fonts->AddFontFromMemoryTTF(const_cast(roboto.data()), roboto.size(), 30, &config); + io.Fonts->AddFontFromMemoryTTF(const_cast(roboto.data()), roboto.size(), 30, &config, range); config.MergeMode = true; config.GlyphMinAdvanceX = 40; // Use if you want to make the icon monospaced diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index c814f795..418567ba 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -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 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 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 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::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, diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index c0ee3a1f..0e370b34 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -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 -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", ¤t_tab, tab::server_list, {TabWidth, 0}); + RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " " + _("Server list"), ¤t_tab, tab::server_list, {TabWidth, 0}); vibrate_on_hover(); - RadioButtonWithoutCheckBox(ICON_FA_GEARS " Settings", ¤t_tab, tab::settings, {TabWidth, 0}); + RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), ¤t_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", ¤t_tab, tab::about, {TabWidth, 0}); + RadioButtonWithoutCheckBox(ICON_FA_CIRCLE_INFO " " + _("About"), ¤t_tab, tab::about, {TabWidth, 0}); vibrate_on_hover(); - RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " Exit", ¤t_tab, tab::exit, {TabWidth, 0}); + RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " " + _("Exit"), ¤t_tab, tab::exit, {TabWidth, 0}); vibrate_on_hover(); ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 86c01d7b..ea21ea05 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -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 subplots; diff --git a/client/scenes/stream_stats.cpp b/client/scenes/stream_stats.cpp index f2afb379..ba42519b 100644 --- a/client/scenes/stream_stats.cpp +++ b/client/scenes/stream_stats.cpp @@ -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(); diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index b864c380..c89c0597 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,5 +1,7 @@ if (BOOST_FOUND) add_library(Boost::pfr ALIAS Boost::headers) +elseif (WIVRN_BUILD_CLIENT) + FetchContent_MakeAvailable(boost) else() FetchContent_MakeAvailable(boostpfr) endif() diff --git a/docs/building.md b/docs/building.md index 59734da9..fc8633c9 100644 --- a/docs/building.md +++ b/docs/building.md @@ -4,7 +4,7 @@ ## Dependencies -WiVRn requires avahi-client, eigen3, libpulse, libsystemd, nlohmann_json. +WiVRn requires avahi-client, eigen3, gettext, libpulse, libsystemd, nlohmann_json. It also requires at least one encoder: diff --git a/tools/check_messages.sh b/tools/check_messages.sh new file mode 100755 index 00000000..e97b24fa --- /dev/null +++ b/tools/check_messages.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +cd $(dirname $0)/.. + +WIVRN_POT=$(mktemp) +xgettext --keyword=_:1,1t --keyword=_S:1,1t --keyword=_F:1,1t client/**/*.cpp --output=$WIVRN_POT --package-name=WiVRn +sed -i 's/charset=CHARSET/charset=UTF-8/g' $WIVRN_POT + +RC=0 + +for i in $(find client/locale -name wivrn.po) +do + msgmerge --quiet --no-fuzzy-matching $i $WIVRN_POT --output-file=$i.new + + pot_creation_date=$(grep -o "POT-Creation-Date: [-0-9:+ ]*" $i) + sed -i "s/POT-Creation-Date: [-0-9:+ ]*/$pot_creation_date/" $i.new + + diff -U 3 -I '#.*' $i $i.new + + if [ $? != 0 ] + then + RC=1 + fi +done + +rm $WIVRN_POT + +exit $RC diff --git a/tools/update_messages.sh b/tools/update_messages.sh new file mode 100755 index 00000000..ca87061a --- /dev/null +++ b/tools/update_messages.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +cd $(dirname $0)/.. + +echo Generating template +WIVRN_POT=$(mktemp) +xgettext --keyword=_:1,1t --keyword=_S:1,1t --keyword=_F:1,1t client/**/*.cpp --output=$WIVRN_POT --package-name=WiVRn +sed -i 's/charset=CHARSET/charset=UTF-8/g' $WIVRN_POT + +for i in $(find client/locale -name wivrn.po) +do + echo Updating $i + msgmerge --quiet --update $i $WIVRN_POT +done + +rm $WIVRN_POT