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
+2 -2
View File
@@ -91,7 +91,7 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: > 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 - name: Configure CMake
run: > run: >
@@ -163,7 +163,7 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: > 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 - name: Check for Secret availability
id: secret-check id: secret-check
+14
View File
@@ -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
+5 -4
View File
@@ -58,15 +58,15 @@ include(VulkanVersion)
if (WIVRN_USE_SYSTEM_BOOST STREQUAL "AUTO") if (WIVRN_USE_SYSTEM_BOOST STREQUAL "AUTO")
if(WIVRN_BUILD_DISSECTOR) if(WIVRN_BUILD_DISSECTOR)
find_package(Boost 1.84.0) find_package(Boost 1.84.0 COMPONENTS locale)
else() else()
find_package(Boost 1.75.0) find_package(Boost 1.75.0 COMPONENTS locale)
endif() endif()
elseif(WIVRN_USE_SYSTEM_BOOST STREQUAL "ON") elseif(WIVRN_USE_SYSTEM_BOOST STREQUAL "ON")
if(WIVRN_BUILD_DISSECTOR) if(WIVRN_BUILD_DISSECTOR)
find_package(Boost 1.84.0 REQUIRED) find_package(Boost 1.84.0 REQUIRED COMPONENTS locale)
else() else()
find_package(Boost 1.75.0 REQUIRED) find_package(Boost 1.75.0 REQUIRED COMPONENTS locale)
endif() endif()
endif() endif()
@@ -164,6 +164,7 @@ endif()
# Common dependencies # Common dependencies
FetchContent_Declare(boostpfr URL https://github.com/boostorg/pfr/archive/refs/tags/2.2.0.tar.gz) 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 # Client dependencies
FetchContent_Declare(simdjson URL https://github.com/simdjson/simdjson/archive/refs/tags/v3.9.3.tar.gz) 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) FetchContent_Declare(fastgltf URL https://github.com/spnda/fastgltf/archive/refs/tags/v0.7.1.tar.gz)
+1
View File
@@ -74,6 +74,7 @@ See [configuration](docs/configuration.md) for configurable items.
WiVRn uses the following software: WiVRn uses the following software:
- [ambientCG](https://ambientcg.com/) - [ambientCG](https://ambientcg.com/)
- [Avahi](https://www.avahi.org/) - [Avahi](https://www.avahi.org/)
- [Boost.Locale](https://github.com/boostorg/locale)
- [Boost.PFR](https://github.com/boostorg/pfr) - [Boost.PFR](https://github.com/boostorg/pfr)
- [Dear ImGui](https://github.com/ocornut/imgui) - [Dear ImGui](https://github.com/ocornut/imgui)
- [fastgltf](https://github.com/spnda/fastgltf) - [fastgltf](https://github.com/spnda/fastgltf)
+30 -1
View File
@@ -9,6 +9,10 @@ set(FASTGLTF_COMPILE_AS_CPP20 ON)
FetchContent_MakeAvailable(simdjson spdlog glm fastgltf imgui stb libktx implot) FetchContent_MakeAvailable(simdjson spdlog glm fastgltf imgui stb libktx implot)
if (NOT BOOST_FOUND)
FetchContent_MakeAvailable(boost)
endif()
include(FreetypeHarfbuzz) include(FreetypeHarfbuzz)
include(CompileGLSL) include(CompileGLSL)
@@ -123,7 +127,7 @@ file(GLOB_RECURSE VULKAN_SHADERS CONFIGURE_DEPENDS "*.glsl")
target_sources(wivrn PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS}) target_sources(wivrn PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS})
wivrn_compile_glsl(wivrn ${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 -DXR_USE_GRAPHICS_API_VULKAN)
target_compile_definitions(wivrn PRIVATE -DVMA_STATS_STRING_ENABLED=0) target_compile_definitions(wivrn PRIVATE -DVMA_STATS_STRING_ENABLED=0)
target_compile_options(wivrn PRIVATE -fdiagnostics-color -Wall -Wextra -pedantic) # -Werror 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 target_link_libraries(wivrn vvl1 vvl2) # Hack to get gradle to package the validation layer in the APK
endif() 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)
+49
View File
@@ -18,6 +18,7 @@
*/ */
#include "application.h" #include "application.h"
#include "asset.h"
#include "openxr/openxr.h" #include "openxr/openxr.h"
#include "scene.h" #include "scene.h"
#include "spdlog/common.h" #include "spdlog/common.h"
@@ -31,6 +32,7 @@
#include "xr/check.h" #include "xr/check.h"
#include "xr/xr.h" #include "xr/xr.h"
#include <algorithm> #include <algorithm>
#include <boost/locale.hpp>
#include <chrono> #include <chrono>
#include <ctype.h> #include <ctype.h>
#include <exception> #include <exception>
@@ -836,6 +838,53 @@ void application::initialize()
initialize_actions(); initialize_actions();
interaction_profile_changed(); 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<jni::object<"java/util/Locale">>("getDefault");
// if (auto language = default_locale.call<jni::string>("toString"))
if (auto language = default_locale.call<jni::string>("getLanguage"))
messages_info.language = language;
if (auto country = default_locale.call<jni::string>("getCountry"))
messages_info.country = country;
messages_info.encoding = "UTF-8";
#else
auto & facet = std::use_facet<boost::locale::info>(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<char> 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<char>(messages_info));
std::locale::global(loc);
} }
std::pair<XrAction, XrActionType> application::get_action(const std::string & requested_name) std::pair<XrAction, XrActionType> application::get_action(const std::string & requested_name)
+15
View File
@@ -29,6 +29,9 @@
#include "vk/vk_allocator.h" #include "vk/vk_allocator.h"
#include "xr/xr.h" #include "xr/xr.h"
#include <atomic> #include <atomic>
#include <boost/locale/generator.hpp>
#include <boost/locale/gnu_gettext.hpp>
#include <boost/locale/message.hpp>
#include <chrono> #include <chrono>
#include <filesystem> #include <filesystem>
#include <glm/glm.hpp> #include <glm/glm.hpp>
@@ -43,6 +46,10 @@
#include <openxr/openxr_platform.h> #include <openxr/openxr_platform.h>
#include <openxr/openxr_reflection.h> #include <openxr/openxr_reflection.h>
#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; class scene;
struct application_info struct application_info
@@ -137,6 +144,9 @@ class application : public singleton<application>
std::optional<configuration> config; std::optional<configuration> config;
boost::locale::generator gen;
boost::locale::gnu_gettext::messages_info messages_info;
void loop(); void loop();
std::mutex debug_report_mutex; std::mutex debug_report_mutex;
@@ -414,4 +424,9 @@ public:
assert(instance().config); assert(instance().config);
return *instance().config; return *instance().config;
} }
static boost::locale::gnu_gettext::messages_info & get_messages_info()
{
return instance().messages_info;
}
}; };
+19
View File
@@ -76,6 +76,7 @@ struct Void
return "V"; return "V";
} }
constexpr static const auto call_method = &_JNIEnv::CallVoidMethod; constexpr static const auto call_method = &_JNIEnv::CallVoidMethod;
constexpr static const auto call_static_method = &_JNIEnv::CallStaticVoidMethod;
}; };
namespace details namespace details
@@ -166,6 +167,21 @@ struct klass
jfieldID id = env.GetStaticFieldID(*this, name.c_str(), T::type().c_str()); jfieldID id = env.GetStaticFieldID(*this, name.c_str(), T::type().c_str());
return T((env.*T::static_field)(*this, id)); return T((env.*T::static_field)(*this, id));
} }
template <typename R, typename... Args>
auto call(const char * method, Args &&... args)
{
using R1 = details::type_map_t<R>;
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>(args)...);
return R(std::apply([&](auto &... t) {
return (env.*R1::call_static_method)(*this, method_id, t...);
},
handles));
}
}; };
struct Bool struct Bool
@@ -175,6 +191,7 @@ struct Bool
return "Z"; return "Z";
} }
constexpr static const auto call_method = &_JNIEnv::CallBooleanMethod; constexpr static const auto call_method = &_JNIEnv::CallBooleanMethod;
constexpr static const auto call_static_method = &_JNIEnv::CallStaticBooleanMethod;
bool value; bool value;
@@ -193,6 +210,7 @@ struct Int
{ {
constexpr static auto static_field = &_JNIEnv::GetStaticIntField; constexpr static auto static_field = &_JNIEnv::GetStaticIntField;
constexpr static const auto call_method = &_JNIEnv::CallIntMethod; constexpr static const auto call_method = &_JNIEnv::CallIntMethod;
constexpr static const auto call_static_method = &_JNIEnv::CallStaticIntMethod;
static std::string type() static std::string type()
{ {
@@ -222,6 +240,7 @@ struct object
std::unique_ptr<std::remove_pointer_t<jobject>, details::deleter> self; std::unique_ptr<std::remove_pointer_t<jobject>, details::deleter> self;
constexpr static const auto call_method = &_JNIEnv::CallObjectMethod; constexpr static const auto call_method = &_JNIEnv::CallObjectMethod;
constexpr static const auto call_static_method = &_JNIEnv::CallStaticObjectMethod;
object(jobject o) object(jobject o)
{ {
+15 -1
View File
@@ -29,11 +29,13 @@
#include "vulkan/vulkan_to_string.hpp" #include "vulkan/vulkan_to_string.hpp"
#include <algorithm> #include <algorithm>
#include <backends/imgui_impl_vulkan.h> #include <backends/imgui_impl_vulkan.h>
#include <boost/locale.hpp>
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
#include <glm/gtc/matrix_access.hpp> #include <glm/gtc/matrix_access.hpp>
#include <imgui.h> #include <imgui.h>
#include <imgui_internal.h> #include <imgui_internal.h>
#include <locale>
#include <optional> #include <optional>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
@@ -104,6 +106,11 @@ static void check_vk_result(VkResult result)
} }
} }
const std::map<std::string, std::vector<ImWchar>> glyph_ranges_per_language =
{
{"fr", {0x0020, 0x017f, 0}} // Basic Latin + Latin Supplement + Latin Extended-A
};
std::optional<std::pair<ImVec2, float>> imgui_context::ray_plane_intersection(const imgui_context::controller_state & in) const std::optional<std::pair<ImVec2, float>> imgui_context::ray_plane_intersection(const imgui_context::controller_state & in) const
{ {
if (!in.active) 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_regular("Font Awesome 6 Free-Regular-400.otf");
asset font_awesome_solid("Font Awesome 6 Free-Solid-900.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; ImFontConfig config;
config.FontDataOwnedByAtlas = false; config.FontDataOwnedByAtlas = false;
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte *>(roboto.data()), roboto.size(), 30, &config); io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte *>(roboto.data()), roboto.size(), 30, &config, range);
config.MergeMode = true; config.MergeMode = true;
config.GlyphMinAdvanceX = 40; // Use if you want to make the icon monospaced config.GlyphMinAdvanceX = 40; // Use if you want to make the icon monospaced
+7 -7
View File
@@ -140,7 +140,7 @@ scenes::lobby::lobby()
} }
if (swapchain_format == vk::Format::eUndefined) 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)); 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"); auto protocol = service.txt.find("protocol");
if (protocol == service.txt.end()) 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) 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 // 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)) if (int err = getaddrinfo(service.hostname.c_str(), nullptr, &hint, &addresses))
{ {
spdlog::error("Cannot resolve hostname {}: {}", service.hostname, gai_strerror(err)); 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) 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) catch (std::exception & e)
{ {
std::string txt = fmt::format("Cannot connect to {} ({}): {}", service.hostname, address_string, e.what()); spdlog::warn("Cannot connect to {} ({}): {}", service.hostname, address_string, e.what());
spdlog::warn(txt); std::string txt = fmt::format(_F("Cannot connect to {} ({}): {}"), service.hostname, address_string, e.what());
if (not error.empty()) if (not error.empty())
error += "\n"; error += "\n";
error += txt; 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>( async_session = utils::async<std::unique_ptr<wivrn_session>, std::string>(
[](auto token, wivrn_discover::service service, bool manual) { [](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); return connect_to_session(service, manual);
}, },
data.service, data.service,
+38 -36
View File
@@ -80,9 +80,9 @@ void scenes::lobby::gui_connecting()
if (next_scene) if (next_scene)
{ {
if (next_scene->current_state() == scenes::stream::state::stalled) if (next_scene->current_state() == scenes::stream::state::stalled)
status = "Video stream interrupted"; status = _("Video stream interrupted");
else else
status = "Waiting for video stream"; status = _("Waiting for video stream");
} }
else if (async_session.valid()) else if (async_session.valid())
status = async_session.get_progress(); status = async_session.get_progress();
@@ -97,14 +97,14 @@ void scenes::lobby::gui_connecting()
std::string button_label; std::string button_label;
if (async_error) if (async_error)
button_label = "Close"; button_label = _("Close");
else else
button_label = "Cancel"; button_label = _("Cancel");
ImGui::Dummy({1000, 1}); ImGui::Dummy({1000, 1});
ImGui::PushFont(imgui_ctx->large_font); ImGui::PushFont(imgui_ctx->large_font);
CenterTextH(fmt::format("Connection to {}", server_name)); CenterTextH(fmt::format(_F("Connection to {}"), server_name));
ImGui::PopFont(); ImGui::PopFont();
// ImGui::TextWrapped("%s", status.first.c_str()); // ImGui::TextWrapped("%s", status.first.c_str());
@@ -132,7 +132,7 @@ void scenes::lobby::gui_add_server()
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("Displayed name"); ImGui::Text("%s", _S("Displayed name"));
static char buf[100]; static char buf[100];
ImGui::TableNextColumn(); ImGui::TableNextColumn();
@@ -141,7 +141,7 @@ void scenes::lobby::gui_add_server()
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("Host name"); ImGui::Text("%s", _S("Host name"));
static char buf2[100]; static char buf2[100];
ImGui::TableNextColumn(); ImGui::TableNextColumn();
@@ -150,7 +150,7 @@ void scenes::lobby::gui_add_server()
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("Port"); ImGui::Text("%s", _S("Port"));
static int port; static int port;
ImGui::TableNextColumn(); ImGui::TableNextColumn();
@@ -214,7 +214,7 @@ void scenes::lobby::gui_server_list()
{ {
ImGui::PushFont(imgui_ctx->large_font); ImGui::PushFont(imgui_ctx->large_font);
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 0.5)); 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::PopStyleColor();
ImGui::PopFont(); ImGui::PopFont();
} }
@@ -243,7 +243,8 @@ void scenes::lobby::gui_server_list()
if (!data.manual) if (!data.manual)
{ {
ImGui::SetCursorPos(ImVec2(pos.x, pos.y + 50)); 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(); config.save();
vibrate_on_hover(); 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_ButtonHovered, ImVec4(0.2f, 0.4f, 0.3f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 0.5f, 0.2f, 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); connect(data);
ImGui::OpenPopup("connecting"); ImGui::OpenPopup("connecting");
@@ -283,9 +285,9 @@ void scenes::lobby::gui_server_list()
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
{ {
if (!data.compatible) if (!data.compatible)
ImGui::SetTooltip("Incompatible server version"); ImGui::SetTooltip("%s", _S("Incompatible server version"));
else if (!data.visible && !data.manual) else if (!data.visible && !data.manual)
ImGui::SetTooltip("Server not available"); ImGui::SetTooltip("%s", _S("Server not available"));
} }
ImGui::PopStyleColor(3); 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_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 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; cookie_to_remove = cookie;
vibrate_on_hover(); vibrate_on_hover();
@@ -343,7 +345,7 @@ void scenes::lobby::gui_settings()
float current = session.get_current_refresh_rate(); float current = session.get_current_refresh_rate();
if (not refresh_rates.empty()) 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) for (float rate: refresh_rates)
{ {
@@ -365,11 +367,11 @@ void scenes::lobby::gui_settings()
const auto current = config.resolution_scale; const auto current = config.resolution_scale;
const auto width = stream_view.recommendedImageRectWidth; const auto width = stream_view.recommendedImageRectWidth;
const auto height = stream_view.recommendedImageRectHeight; 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) 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.resolution_scale = scale;
config.save(); config.save();
@@ -380,7 +382,7 @@ void scenes::lobby::gui_settings()
vibrate_on_hover(); vibrate_on_hover();
} }
if (ImGui::Checkbox("Enable microphone", &config.microphone)) if (ImGui::Checkbox(_S("Enable microphone"), &config.microphone))
{ {
#ifdef __ANDROID__ #ifdef __ANDROID__
if (config.microphone) if (config.microphone)
@@ -408,7 +410,7 @@ void scenes::lobby::gui_settings()
vibrate_on_hover(); vibrate_on_hover();
ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough); 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(); setup_passthrough();
config.save(); config.save();
@@ -416,7 +418,7 @@ void scenes::lobby::gui_settings()
vibrate_on_hover(); vibrate_on_hover();
ImGui::EndDisabled(); 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(); config.save();
vibrate_on_hover(); 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_AxisBgActive, IM_COL32(0, 0, 0, 0));
ImPlot::PushStyleColor(ImPlotCol_AxisBgHovered, 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); 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::SetupAxesLimits(0, cpu_time.size() - 1, min_v, max_v, ImGuiCond_Always);
ImPlot::SetNextLineStyle(col); ImPlot::SetNextLineStyle(col);
ImPlot::SetNextFillStyle(col, 0.25); 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(); ImPlot::EndPlot();
} }
ImGui::SameLine(); 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); 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::SetupAxesLimits(0, gpu_time.size() - 1, min_v, max_v, ImGuiCond_Always);
ImPlot::SetNextLineStyle(col); ImPlot::SetNextLineStyle(col);
ImPlot::SetNextFillStyle(col, 0.25); 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::EndPlot();
} }
ImPlot::PopStyleColor(5); ImPlot::PopStyleColor(5);
@@ -491,7 +493,7 @@ void scenes::lobby::gui_about()
ImGui::Image(about_picture, {win_width / 2, win_width / 2}); 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(); ImGuiWindow * window = ImGui::GetCurrentWindow();
if (window->SkipItems) if (window->SkipItems)
@@ -499,8 +501,8 @@ static bool RadioButtonWithoutCheckBox(const char * label, bool active, ImVec2 s
ImGuiContext & g = *GImGui; ImGuiContext & g = *GImGui;
const ImGuiStyle & style = g.Style; const ImGuiStyle & style = g.Style;
const ImGuiID id = window->GetID(label); const ImGuiID id = window->GetID(label.c_str());
const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); const ImVec2 label_size = ImGui::CalcTextSize(label.c_str(), NULL, true);
const ImVec2 pos = window->DC.CursorPos; 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); ImGui::RenderFrame(bb.Min, bb.Max, ImGui::GetColorU32(col), true, style.FrameRounding);
ImVec2 TextAlign{0, 0.5f}; 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; return pressed;
} }
template <typename T> 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); const bool pressed = RadioButtonWithoutCheckBox(label, *v == v_button, size_arg);
if (pressed) 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::BeginChild("Tabs", {TabWidth, ImGui::GetContentRegionMax().y - ImGui::GetWindowContentRegionMin().y});
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10)); 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(); 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(); vibrate_on_hover();
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 2 * ImGui::GetCurrentContext()->FontSize - 4 * style.FramePadding.y - style.ItemSpacing.y - style.WindowPadding.y); 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(); 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(); vibrate_on_hover();
ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding
+2 -2
View File
@@ -185,10 +185,10 @@ private:
struct plot struct plot
{ {
const char * title; std::string title;
struct subplot struct subplot
{ {
const char * title; std::string title;
float scenes::stream::global_metric::*data; float scenes::stream::global_metric::*data;
}; };
std::vector<subplot> subplots; 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 = { static const std::array plots = {
// clang-format off // 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}, plot(_("GPU time"), {{_("Reproject"), &global_metric::gpu_time},
{"Blit", &global_metric::gpu_barrier}}, "s"), {_("Blit"), &global_metric::gpu_barrier}}, "s"),
plot("Network", {{"Download", &global_metric::bandwidth_rx}, plot(("Network"), {{_("Download"), &global_metric::bandwidth_rx},
{"Upload", &global_metric::bandwidth_tx}}, "bit/s"), {_("Upload"), &global_metric::bandwidth_tx}}, "bit/s"),
// clang-format on // clang-format on
}; };
@@ -170,7 +170,7 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
int n = 0; int n = 0;
for (const auto & [title, subplots, unit]: plots) 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 min_v = 0;
float max_v = 0; float max_v = 0;
@@ -202,7 +202,7 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
.count = (int)global_metrics.size(), .count = (int)global_metrics.size(),
.multiplier = multiplier, .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(); ImPlot::EndPlot();
} }
@@ -213,7 +213,7 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
for (auto && [index, metrics]: utils::enumerate(decoder_metrics)) 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)) if (ImPlot::BeginPlot(title.c_str(), plot_size, ImPlotFlags_NoTitle | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText | ImPlotFlags_NoChild))
{ {
float min_v = 0; float min_v = 0;
@@ -225,8 +225,8 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
else else
axis_scale[n] = 0.99 * axis_scale[n] + 0.01 * max_v; axis_scale[n] = 0.99 * axis_scale[n] + 0.01 * max_v;
const char * title_with_units = "Timings [ms]"; std::string title_with_units = _("Timings [ms]");
ImPlot::SetupAxes(nullptr, title_with_units, ImPlotAxisFlags_NoDecorations, 0); 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); ImPlot::SetupAxesLimits(0, metrics.size() - 1, min_v * 1e3f, axis_scale[n] * 1e3f, ImGuiCond_Always);
getter_data getter_send_begin{ getter_data getter_send_begin{
@@ -286,11 +286,11 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
.multiplier = 1e3f}; .multiplier = 1e3f};
// clang-format off // clang-format off
ImPlot::PlotShadedG("Send", getter, &getter_send_begin, getter, &getter_send_end, metrics.size()); ImPlot::PlotShadedG(_S("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(_S("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::PlotShadedG(_S("Decode"), getter, &getter_sent_to_decoder, getter, &getter_received_from_decoder, metrics.size());
ImPlot::PlotLineG("Blitted", getter, &getter_blitted, metrics.size()); ImPlot::PlotLineG(_S("Blitted"), getter, &getter_blitted, metrics.size());
ImPlot::PlotLineG("Displayed", getter, &getter_displayed, metrics.size()); ImPlot::PlotLineG(_S("Displayed"), getter, &getter_displayed, metrics.size());
// clang-format on // clang-format on
ImPlot::EndPlot(); ImPlot::EndPlot();
+2
View File
@@ -1,5 +1,7 @@
if (BOOST_FOUND) if (BOOST_FOUND)
add_library(Boost::pfr ALIAS Boost::headers) add_library(Boost::pfr ALIAS Boost::headers)
elseif (WIVRN_BUILD_CLIENT)
FetchContent_MakeAvailable(boost)
else() else()
FetchContent_MakeAvailable(boostpfr) FetchContent_MakeAvailable(boostpfr)
endif() endif()
+1 -1
View File
@@ -4,7 +4,7 @@
## Dependencies ## 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: It also requires at least one encoder:
+28
View File
@@ -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
+16
View File
@@ -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