Additional localization fixes (#966)

This commit is contained in:
Francesco Saltori 2023-09-14 12:47:59 +02:00 committed by GitHub
parent c66ab0c51a
commit 96800c6f97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 68 additions and 123 deletions

View file

@ -1,5 +1,7 @@
#pragma once
#define wxNO_UNSAFE_WXSTRING_CONV 1
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
@ -36,67 +38,6 @@
extern bool g_inputConfigWindowHasFocus;
// wx helper functions
#include <wx/string.h>
struct wxStringFormatParameters
{
sint32 parameter_index;
sint32 parameter_count;
wchar_t* token_buffer;
wchar_t* substitude_parameter;
};
template <typename ...Args>
wxString wxStringFormat(std::wstring& format, wxStringFormatParameters& parameters)
{
return format;
}
template <typename T, typename ...Args>
wxString wxStringFormat(std::wstring& format, wxStringFormatParameters& parameters, T arg, Args... args)
{
wchar_t tmp[64];
swprintf(tmp, 64, LR"(\{[%d]+\})", parameters.parameter_index);
const std::wregex placeholder_regex(tmp);
auto result = format;
while (std::regex_search(result, placeholder_regex))
{
result = std::regex_replace(result, placeholder_regex, parameters.substitude_parameter, std::regex_constants::format_first_only);
result = wxString::Format(wxString(result), arg);
}
parameters.parameter_index++;
if (parameters.parameter_index == parameters.parameter_count)
return result;
parameters.substitude_parameter = std::wcstok(nullptr, LR"( )", &parameters.token_buffer);
return wxStringFormat(result, parameters, args...);
}
template <typename ...T>
wxString wxStringFormat(const wxString& format, const wchar_t* parameters, T... args)
{
const auto parameter_count = std::count(parameters, parameters + wcslen(parameters), '%');
if (parameter_count == 0)
return format;
const auto copy = wcsdup(parameters);
wxStringFormatParameters para;
para.substitude_parameter = std::wcstok(copy, LR"( )", &para.token_buffer);
para.parameter_count = parameter_count;
para.parameter_index = 0;
auto tmp_string = format.ToStdWstring();
auto result = wxStringFormat(tmp_string, para, args...);
free(copy);
return result;
}
inline bool SendSliderEvent(wxSlider* slider, int new_value)
{
wxCommandEvent cevent(wxEVT_SLIDER, slider->GetId());