1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00

Qt/overlays: use Argument list for translatable strings

This is somewhat crippled for now. It only takes a single argument in the callback
This commit is contained in:
Megamouse 2020-09-03 18:30:46 +02:00
parent 460a933267
commit d0ffbbfc4d
11 changed files with 59 additions and 73 deletions

View File

@ -128,8 +128,7 @@ namespace rsx
default: break;
}
text_view.set_text(trophy.name);
text_view.set_text(get_localized_u32string(string_id) + text_view.text);
text_view.set_text(get_localized_u32string(string_id, trophy.name));
text_view.auto_resize();
// Resize background to cover the text

View File

@ -51,8 +51,8 @@ struct EmuCallbacks
std::function<std::shared_ptr<class OskDialogBase>()> get_osk_dialog;
std::function<std::unique_ptr<class SaveDialogBase>()> get_save_dialog;
std::function<std::unique_ptr<class TrophyNotificationBase>()> get_trophy_notification_dialog;
std::function<std::string(localized_string_id)> get_localized_string;
std::function<std::u32string(localized_string_id)> get_localized_u32string;
std::function<std::string(localized_string_id, const char*)> get_localized_string;
std::function<std::u32string(localized_string_id, const char*)> get_localized_u32string;
};
class Emulator final

View File

@ -2,12 +2,12 @@
#include "localized_string.h"
#include "System.h"
std::string get_localized_string(localized_string_id id)
std::string get_localized_string(localized_string_id id, const char* args)
{
return Emu.GetCallbacks().get_localized_string(id);
return Emu.GetCallbacks().get_localized_string(id, args);
}
std::u32string get_localized_u32string(localized_string_id id)
std::u32string get_localized_u32string(localized_string_id id, const char* args)
{
return Emu.GetCallbacks().get_localized_u32string(id);
return Emu.GetCallbacks().get_localized_u32string(id, args);
}

View File

@ -30,5 +30,5 @@ enum class localized_string_id
RSX_OVERLAYS_LIST_CANCEL,
};
std::string get_localized_string(localized_string_id id);
std::u32string get_localized_u32string(localized_string_id id);
std::string get_localized_string(localized_string_id id, const char* args = "");
std::u32string get_localized_u32string(localized_string_id id, const char* args = "");

View File

@ -98,8 +98,8 @@ void headless_application::InitializeCallbacks()
callbacks.on_stop = []() {};
callbacks.on_ready = []() {};
callbacks.get_localized_string = [](localized_string_id) -> std::string { return {}; };
callbacks.get_localized_u32string = [](localized_string_id) -> std::u32string { return {}; };
callbacks.get_localized_string = [](localized_string_id, const char*) -> std::string { return {}; };
callbacks.get_localized_u32string = [](localized_string_id, const char*) -> std::u32string { return {}; };
Emu.SetCallbacks(std::move(callbacks));
}

View File

@ -1575,7 +1575,6 @@
<ClCompile Include="rpcs3qt\gui_application.cpp" />
<ClCompile Include="rpcs3qt\input_dialog.cpp" />
<ClCompile Include="rpcs3qt\localized.cpp" />
<ClCompile Include="rpcs3qt\localized_emu.cpp" />
<ClCompile Include="rpcs3qt\microphone_creator.cpp" />
<ClCompile Include="rpcs3qt\osk_dialog_frame.cpp" />
<ClCompile Include="rpcs3qt\pad_led_settings_dialog.cpp" />

View File

@ -1090,9 +1090,6 @@
<ClCompile Include="QTGeneratedFiles\Debug - LLVM\moc_rpcn_settings_dialog.cpp">
<Filter>Generated Files\Debug - LLVM</Filter>
</ClCompile>
<ClCompile Include="rpcs3qt\localized_emu.cpp">
<Filter>Gui\settings</Filter>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Release - LLVM\moc_localized_emu.cpp">
<Filter>Generated Files\Release - LLVM</Filter>
</ClCompile>

View File

@ -28,7 +28,6 @@
instruction_editor_dialog.cpp
kernel_explorer.cpp
localized.cpp
localized_emu.cpp
log_frame.cpp
main_window.cpp
memory_string_searcher.cpp

View File

@ -359,14 +359,14 @@ void gui_application::InitializeCallbacks()
}
};
callbacks.get_localized_string = [](localized_string_id id) -> std::string
callbacks.get_localized_string = [](localized_string_id id, const char* args) -> std::string
{
return localized_emu::get_string(id);
return localized_emu::get_string(id, args);
};
callbacks.get_localized_u32string = [](localized_string_id id) -> std::u32string
callbacks.get_localized_u32string = [](localized_string_id id, const char* args) -> std::u32string
{
return localized_emu::get_u32string(id);
return localized_emu::get_u32string(id, args);
};
Emu.SetCallbacks(std::move(callbacks));

View File

@ -1,48 +0,0 @@
#include <QString>
#include "localized_emu.h"
localized_emu::localized_emu()
{
}
QString localized_emu::translated(localized_string_id id)
{
switch (id)
{
case localized_string_id::RSX_OVERLAYS_TROPHY_BRONZE: return tr("You have earned the bronze trophy\n");
case localized_string_id::RSX_OVERLAYS_TROPHY_SILVER: return tr("You have earned the silver trophy\n");
case localized_string_id::RSX_OVERLAYS_TROPHY_GOLD: return tr("You have earned the gold trophy\n");
case localized_string_id::RSX_OVERLAYS_TROPHY_PLATINUM: return tr("You have earned the platinum trophy\n");
case localized_string_id::RSX_OVERLAYS_COMPILING_SHADERS: return tr("Compiling shaders");
case localized_string_id::RSX_OVERLAYS_MSG_DIALOG_YES: return tr("Yes");
case localized_string_id::RSX_OVERLAYS_MSG_DIALOG_NO: return tr("No");
case localized_string_id::RSX_OVERLAYS_MSG_DIALOG_CANCEL: return tr("Cancel");
case localized_string_id::RSX_OVERLAYS_MSG_DIALOG_OK: return tr("OK");
case localized_string_id::RSX_OVERLAYS_SAVE_DIALOG_TITLE: return tr("Save Dialog");
case localized_string_id::RSX_OVERLAYS_SAVE_DIALOG_DELETE: return tr("Delete Save");
case localized_string_id::RSX_OVERLAYS_SAVE_DIALOG_LOAD: return tr("Load Save");
case localized_string_id::RSX_OVERLAYS_SAVE_DIALOG_SAVE: return tr("Save");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_ACCEPT: return tr("Accept");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_CANCEL: return tr("Cancel");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_SPACE: return tr("Space");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_BACKSPACE: return tr("Backspace");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_SHIFT: return tr("Shift");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_ENTER_TEXT: return tr("[Enter Text]");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_ENTER_PASSWORD: return tr("[Enter Password]");
case localized_string_id::RSX_OVERLAYS_LIST_SELECT: return tr("Select");
case localized_string_id::RSX_OVERLAYS_LIST_CANCEL: return tr("Cancel");
case localized_string_id::INVALID: return tr("Invalid");
default: return tr("Unknown");
}
}
std::string localized_emu::get_string(localized_string_id id)
{
return translated(id).toStdString();
}
std::u32string localized_emu::get_u32string(localized_string_id id)
{
return translated(id).toStdU32String();
}

View File

@ -14,11 +14,51 @@ class localized_emu : public QObject
Q_OBJECT
public:
localized_emu();
localized_emu() = default;
static std::string get_string(localized_string_id id);
static std::u32string get_u32string(localized_string_id id);
template <typename... Args>
static std::string get_string(localized_string_id id, Args&&... args)
{
return translated(id, std::forward<Args>(args)...).toStdString();
}
template <typename... Args>
static std::u32string get_u32string(localized_string_id id, Args&&... args)
{
return translated(id, std::forward<Args>(args)...).toStdU32String();
}
private:
static QString translated(localized_string_id id);
template <typename... Args>
static QString translated(localized_string_id id, Args&&... args)
{
switch (id)
{
case localized_string_id::RSX_OVERLAYS_TROPHY_BRONZE: return tr("You have earned the bronze trophy\n%0").arg(std::forward<Args>(args)...);
case localized_string_id::RSX_OVERLAYS_TROPHY_SILVER: return tr("You have earned the silver trophy\n%0").arg(std::forward<Args>(args)...);
case localized_string_id::RSX_OVERLAYS_TROPHY_GOLD: return tr("You have earned the gold trophy\n%0").arg(std::forward<Args>(args)...);
case localized_string_id::RSX_OVERLAYS_TROPHY_PLATINUM: return tr("You have earned the platinum trophy\n%0").arg(std::forward<Args>(args)...);
case localized_string_id::RSX_OVERLAYS_COMPILING_SHADERS: return tr("Compiling shaders");
case localized_string_id::RSX_OVERLAYS_MSG_DIALOG_YES: return tr("Yes");
case localized_string_id::RSX_OVERLAYS_MSG_DIALOG_NO: return tr("No");
case localized_string_id::RSX_OVERLAYS_MSG_DIALOG_CANCEL: return tr("Cancel");
case localized_string_id::RSX_OVERLAYS_MSG_DIALOG_OK: return tr("OK");
case localized_string_id::RSX_OVERLAYS_SAVE_DIALOG_TITLE: return tr("Save Dialog");
case localized_string_id::RSX_OVERLAYS_SAVE_DIALOG_DELETE: return tr("Delete Save");
case localized_string_id::RSX_OVERLAYS_SAVE_DIALOG_LOAD: return tr("Load Save");
case localized_string_id::RSX_OVERLAYS_SAVE_DIALOG_SAVE: return tr("Save");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_ACCEPT: return tr("Accept");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_CANCEL: return tr("Cancel");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_SPACE: return tr("Space");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_BACKSPACE: return tr("Backspace");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_SHIFT: return tr("Shift");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_ENTER_TEXT: return tr("[Enter Text]");
case localized_string_id::RSX_OVERLAYS_OSK_DIALOG_ENTER_PASSWORD: return tr("[Enter Password]");
case localized_string_id::RSX_OVERLAYS_LIST_SELECT: return tr("Select");
case localized_string_id::RSX_OVERLAYS_LIST_CANCEL: return tr("Cancel");
case localized_string_id::INVALID: return tr("Invalid");
default: return tr("Unknown");
}
}
};