Add translation function with formatting

This commit is contained in:
SSimco 2025-07-10 20:27:52 +03:00
parent e6e6e1631e
commit b95f8331a8
5 changed files with 20 additions and 8 deletions

View File

@ -108,7 +108,7 @@ void KeyCache_Prepare()
continue;
if( strishex(line) == false )
{
auto errorMsg = fmt::format(fmt::runtime(_tr("Error in keys.txt at line {}")), lineNumber);
auto errorMsg = _tr("Error in keys.txt at line {}", lineNumber);
WindowSystem::showErrorDialog(errorMsg, WindowSystem::ErrorCategory::KEYS_TXT_CREATION);
continue;
}

View File

@ -43,9 +43,9 @@ void PatchErrorHandler::showStageErrorMessageBox()
if (m_gp)
{
if (m_stage == STAGE::PARSER)
errorMsg.assign(fmt::format(fmt::runtime(_tr("Failed to load patches for graphic pack \'{}\'")), m_gp->GetName()));
errorMsg.assign(_tr("Failed to load patches for graphic pack \'{}\'", m_gp->GetName()));
else
errorMsg.assign(fmt::format(fmt::runtime(_tr("Failed to apply patches for graphic pack \'{}\'")), m_gp->GetName()));
errorMsg.assign(_tr("Failed to apply patches for graphic pack \'{}\'", m_gp->GetName()));
}
else
{

View File

@ -91,7 +91,7 @@ void MMURange::mapMem()
cemu_assert_debug(!m_isMapped);
if (MemMapper::AllocateMemory(memory_base + baseAddress, size, MemMapper::PAGE_PERMISSION::P_RW, true) == nullptr)
{
std::string errorMsg = fmt::format(fmt::runtime(_tr("Unable to allocate {} memory")), name);
std::string errorMsg = _tr("Unable to allocate {} memory", name);
WindowSystem::showErrorDialog(errorMsg, _tr("Error"));
#if BOOST_OS_WINDOWS
ExitProcess(-1);

View File

@ -132,12 +132,24 @@ inline void SetTranslationCallback(std::function<std::string(std::string_view)>
#define TR_NOOP(str) str
inline std::string _tr(std::string_view msgId)
inline std::string _tr(std::string_view text)
{
if (g_translate)
return g_translate(msgId);
return g_translate(text);
return std::string{msgId};
return std::string{text};
}
template<typename... TArgs>
inline std::string _tr(fmt::format_string<TArgs...> text, TArgs... args)
{
if (g_translate)
{
std::string_view textSV{text.get().data(), text.get().size()};
return fmt::format(fmt::runtime(g_translate(textSV)), std::forward<TArgs>(args)...);
}
return fmt::format(text, std::forward<TArgs>(args)...);
}
// manual endian-swapping

View File

@ -30,7 +30,7 @@ private:
wxTimer* m_controllerTimer{ nullptr };
const wxSize m_minButtonSize{ 250, 45 };
const wxString m_disabledHotkeyText{ _("----") };
const wxString m_editModeHotkeyText{ _("") };
const wxString m_editModeHotkeyText{ "" };
std::vector<HotkeyEntry> m_hotkeys;
std::weak_ptr<ControllerBase> m_activeController{};