Localization improvements and fixes (#956)

This commit is contained in:
Francesco Saltori 2023-09-08 02:09:03 +02:00 committed by GitHub
parent 4d1864c8a1
commit c16e258c93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 229 additions and 356 deletions

View file

@ -432,13 +432,11 @@ wxString wxDownloadManagerList::GetTitleEntryText(const TitleEntry& entry, ItemC
switch (column)
{
case ColumnTitleId:
return wxStringFormat2("{:08x}-{:08x}", (uint32)(entry.titleId >> 32), (uint32)(entry.titleId & 0xFFFFFFFF));
return formatWxString("{:08x}-{:08x}", (uint32) (entry.titleId >> 32), (uint32) (entry.titleId & 0xFFFFFFFF));
case ColumnName:
{
return entry.name;
}
case ColumnType:
return wxStringFormat2("{}", entry.type);
return GetTranslatedTitleEntryType(entry.type);
case ColumnVersion:
{
// dont show version for base game unless it is not v0
@ -446,7 +444,7 @@ wxString wxDownloadManagerList::GetTitleEntryText(const TitleEntry& entry, ItemC
return "";
if (entry.type == EntryType::DLC && entry.version == 0)
return "";
return wxStringFormat2("v{}", entry.version);
return formatWxString("v{}", entry.version);
}
case ColumnProgress:
{
@ -454,11 +452,11 @@ wxString wxDownloadManagerList::GetTitleEntryText(const TitleEntry& entry, ItemC
{
if (entry.progress >= 1000)
return "100%";
return wxStringFormat2("{:.1f}%", (float)entry.progress / 10.0f); // one decimal
return formatWxString("{:.1f}%", (float) entry.progress / 10.0f); // one decimal
}
else if (entry.status == TitleDownloadStatus::Installing || entry.status == TitleDownloadStatus::Checking || entry.status == TitleDownloadStatus::Verifying)
{
return wxStringFormat2("{0}/{1}", entry.progress, entry.progressMax); // number of processed files/content files
return formatWxString("{0}/{1}", entry.progress, entry.progressMax); // number of processed files/content files
}
return "";
}
@ -503,6 +501,21 @@ wxString wxDownloadManagerList::GetTitleEntryText(const TitleEntry& entry, ItemC
return wxEmptyString;
}
std::string wxDownloadManagerList::GetTranslatedTitleEntryType(EntryType type)
{
switch (type)
{
case EntryType::Base:
return _("base").utf8_string();
case EntryType::Update:
return _("update").utf8_string();
case EntryType::DLC:
return _("DLC").utf8_string();
default:
return std::to_string(static_cast<std::underlying_type_t<EntryType>>(type));
}
}
void wxDownloadManagerList::AddOrUpdateTitle(TitleEntryData_t* obj)
{
const auto& data = obj->GetData();

View file

@ -150,25 +150,6 @@ private:
bool SortFunc(std::span<int> sortColumnOrder, const Type_t& v1, const Type_t& v2);
static wxString GetTitleEntryText(const TitleEntry& entry, ItemColumn column);
static std::string GetTranslatedTitleEntryType(EntryType entryType);
std::future<bool> m_context_worker;
};
template <>
struct fmt::formatter<wxDownloadManagerList::EntryType> : formatter<string_view>
{
using base = fmt::formatter<fmt::string_view>;
template <typename FormatContext>
auto format(const wxDownloadManagerList::EntryType& type, FormatContext& ctx)
{
switch (type)
{
case wxDownloadManagerList::EntryType::Base:
return base::format("base", ctx);
case wxDownloadManagerList::EntryType::Update:
return base::format("update", ctx);
case wxDownloadManagerList::EntryType::DLC:
return base::format("DLC", ctx);
}
return base::format(std::to_string(static_cast<std::underlying_type_t<wxDownloadManagerList::EntryType>>(type)), ctx);
}
};

View file

@ -633,7 +633,7 @@ void wxGameList::OnContextMenuSelected(wxCommandEvent& event)
if(dialog.ShowModal() == wxID_OK)
{
const auto custom_name = dialog.GetValue();
GetConfig().SetGameListCustomName(title_id, wxHelper::MakeUTF8(custom_name));
GetConfig().SetGameListCustomName(title_id, custom_name.utf8_string());
m_name_cache.clear();
g_config.Save();
// update list entry
@ -1036,8 +1036,8 @@ void wxGameList::OnGameEntryUpdatedByTitleId(wxTitleIdEvent& event)
const auto region_text = fmt::format("{}", gameInfo.GetRegion());
SetItem(index, ColumnRegion, _(region_text));
SetItem(index, ColumnTitleID, _(fmt::format("{:016x}", titleId)));
SetItem(index, ColumnRegion, wxGetTranslation(region_text));
SetItem(index, ColumnTitleID, fmt::format("{:016x}", titleId));
}
else if (m_style == Style::kIcons)
{
@ -1124,7 +1124,7 @@ void wxGameList::HandleTitleListCallback(CafeTitleListCallbackEvent* evt)
void wxGameList::RemoveCache(const std::list<fs::path>& cachePaths, const std::string& titleName)
{
wxMessageDialog dialog(this, fmt::format(fmt::runtime(_("Remove the shader caches for {}?").ToStdString()), titleName), _("Remove shader caches"), wxCENTRE | wxYES_NO | wxICON_EXCLAMATION);
wxMessageDialog dialog(this, formatWxString(_("Remove the shader caches for {}?"), titleName), _("Remove shader caches"), wxCENTRE | wxYES_NO | wxICON_EXCLAMATION);
dialog.SetYesNoLabels(_("Yes"), _("No"));
const auto dialogResult = dialog.ShowModal();
@ -1139,7 +1139,7 @@ void wxGameList::RemoveCache(const std::list<fs::path>& cachePaths, const std::s
if (errs.empty())
wxMessageDialog(this, _("The shader caches were removed!"), _("Shader caches removed"), wxCENTRE | wxOK | wxICON_INFORMATION).ShowModal();
else
wxMessageDialog(this, fmt::format(fmt::runtime(_("Failed to remove the shader caches:\n{}").ToStdString()), fmt::join(errs, "\n")), _("Error"), wxCENTRE | wxOK | wxICON_ERROR).ShowModal();
wxMessageDialog(this, formatWxString(_("Failed to remove the shader caches:\n{}"), fmt::join(errs, "\n")), _("Error"), wxCENTRE | wxOK | wxICON_ERROR).ShowModal();
}
void wxGameList::AsyncWorkerThread()
@ -1265,13 +1265,13 @@ void wxGameList::CreateShortcut(GameInfo2& gameInfo) {
// In most cases it should find it
if (!result_index){
wxMessageBox("Icon is yet to load, so will not be used by the shortcut", "Warning", wxOK | wxCENTRE | wxICON_WARNING);
wxMessageBox(_("Icon is yet to load, so will not be used by the shortcut"), _("Warning"), wxOK | wxCENTRE | wxICON_WARNING);
}
else {
const fs::path out_icon_dir = ActiveSettings::GetUserDataPath("icons");
if (!fs::exists(out_icon_dir) && !fs::create_directories(out_icon_dir)){
wxMessageBox("Cannot access the icon directory, the shortcut will have no icon", "Warning", wxOK | wxCENTRE | wxICON_WARNING);
wxMessageBox(_("Cannot access the icon directory, the shortcut will have no icon"), _("Warning"), wxOK | wxCENTRE | wxICON_WARNING);
}
else {
icon_path = out_icon_dir / fmt::format("{:016x}.png", gameInfo.GetBaseTitleId());
@ -1282,7 +1282,7 @@ void wxGameList::CreateShortcut(GameInfo2& gameInfo) {
wxPNGHandler pngHandler;
if (!pngHandler.SaveFile(&image, png_file, false)) {
icon_path = std::nullopt;
wxMessageBox("The icon was unable to be saved, the shortcut will have no icon", "Warning", wxOK | wxCENTRE | wxICON_WARNING);
wxMessageBox(_("The icon was unable to be saved, the shortcut will have no icon"), _("Warning"), wxOK | wxCENTRE | wxICON_WARNING);
}
}
}
@ -1306,7 +1306,7 @@ void wxGameList::CreateShortcut(GameInfo2& gameInfo) {
std::ofstream output_stream(output_path);
if (!output_stream.good())
{
const wxString errorMsg = fmt::format("Failed to save desktop entry to {}", output_path.utf8_string());
auto errorMsg = formatWxString(_("Failed to save desktop entry to {}"), output_path.utf8_string());
wxMessageBox(errorMsg, _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
return;
}

View file

@ -303,29 +303,29 @@ void wxTitleManagerList::OnConvertToCompressedFormat(uint64 titleId, uint64 righ
}
}
std::string msg = wxHelper::MakeUTF8(_("The following content will be converted to a compressed Wii U archive file (.wua):"));
wxString msg = _("The following content will be converted to a compressed Wii U archive file (.wua):");
msg.append("\n \n");
if (titleInfo_base.IsValid())
msg.append(fmt::format(fmt::runtime(wxHelper::MakeUTF8(_("Base game:\n{}"))), titleInfo_base.GetPrintPath()));
msg.append(formatWxString(_("Base game:\n{}"), titleInfo_base.GetPrintPath()));
else
msg.append(fmt::format(fmt::runtime(wxHelper::MakeUTF8(_("Base game:\nNot installed")))));
msg.append(_("Base game:\nNot installed"));
msg.append("\n\n");
if (titleInfo_update.IsValid())
msg.append(fmt::format(fmt::runtime(wxHelper::MakeUTF8(_("Update:\n{}"))), titleInfo_update.GetPrintPath()));
msg.append(formatWxString(_("Update:\n{}"), titleInfo_update.GetPrintPath()));
else
msg.append(fmt::format(fmt::runtime(wxHelper::MakeUTF8(_("Update:\nNot installed")))));
msg.append(_("Update:\nNot installed"));
msg.append("\n\n");
if (titleInfo_aoc.IsValid())
msg.append(fmt::format(fmt::runtime(wxHelper::MakeUTF8(_("DLC:\n{}"))), titleInfo_aoc.GetPrintPath()));
msg.append(formatWxString(_("DLC:\n{}"), titleInfo_aoc.GetPrintPath()));
else
msg.append(fmt::format(fmt::runtime(wxHelper::MakeUTF8(_("DLC:\nNot installed")))));
msg.append(_("DLC:\nNot installed"));
const int answer = wxMessageBox(wxString::FromUTF8(msg), _("Confirmation"), wxOK | wxCANCEL | wxCENTRE | wxICON_QUESTION, this);
const int answer = wxMessageBox(msg, _("Confirmation"), wxOK | wxCANCEL | wxCENTRE | wxICON_QUESTION, this);
if (answer != wxOK)
return;
std::vector<TitleInfo*> titlesToConvert;
@ -732,7 +732,7 @@ void wxTitleManagerList::OnItemSelected(wxListEvent& event)
// return;;
//}
//m_tooltip_text->SetLabel(wxStringFormat2("{}\n{}", msg, _("You can use the context menu to fix it.")));
//m_tooltip_text->SetLabel(formatWxString("{}\n{}", msg, _("You can use the context menu to fix it.")));
//m_tooltip_window->Fit();
//m_tooltip_timer->StartOnce(250);
}
@ -792,9 +792,9 @@ bool wxTitleManagerList::DeleteEntry(long index, const TitleEntry& entry)
wxString msg;
const bool is_directory = fs::is_directory(entry.path);
if(is_directory)
msg = wxStringFormat2(_("Are you really sure that you want to delete the following folder:\n{}"), wxHelper::FromUtf8(_pathToUtf8(entry.path)));
msg = formatWxString(_("Are you really sure that you want to delete the following folder:\n{}"), _pathToUtf8(entry.path));
else
msg = wxStringFormat2(_("Are you really sure that you want to delete the following file:\n{}"), wxHelper::FromUtf8(_pathToUtf8(entry.path)));
msg = formatWxString(_("Are you really sure that you want to delete the following file:\n{}"), _pathToUtf8(entry.path));
const auto result = wxMessageBox(msg, _("Warning"), wxYES_NO | wxCENTRE | wxICON_EXCLAMATION, this);
if (result == wxNO)
@ -835,7 +835,7 @@ bool wxTitleManagerList::DeleteEntry(long index, const TitleEntry& entry)
if(ec)
{
const auto error_msg = wxStringFormat2(_("Error when trying to delete the entry:\n{}"), GetSystemErrorMessage(ec));
const auto error_msg = formatWxString(_("Error when trying to delete the entry:\n{}"), GetSystemErrorMessage(ec));
wxMessageBox(error_msg, _("Error"), wxOK|wxCENTRE, this);
return false;
}
@ -922,15 +922,15 @@ wxString wxTitleManagerList::GetTitleEntryText(const TitleEntry& entry, ItemColu
switch (column)
{
case ColumnTitleId:
return wxStringFormat2("{:08x}-{:08x}", (uint32)(entry.title_id >> 32), (uint32)(entry.title_id & 0xFFFFFFFF));
return formatWxString("{:08x}-{:08x}", (uint32) (entry.title_id >> 32), (uint32) (entry.title_id & 0xFFFFFFFF));
case ColumnName:
return entry.name;
case ColumnType:
return wxStringFormat2("{}", entry.type);
return GetTranslatedTitleEntryType(entry.type);
case ColumnVersion:
return wxStringFormat2("{}", entry.version);
return formatWxString("{}", entry.version);
case ColumnRegion:
return wxStringFormat2("{}", entry.region); // TODO its a flag so formatter is currently not correct
return wxGetTranslation(fmt::format("{}", entry.region));
case ColumnFormat:
{
if (entry.type == EntryType::Save)
@ -945,7 +945,6 @@ wxString wxTitleManagerList::GetTitleEntryText(const TitleEntry& entry, ItemColu
return _("WUA");
}
return "";
//return wxStringFormat2("{}", entry.format);
}
case ColumnLocation:
{
@ -964,6 +963,25 @@ wxString wxTitleManagerList::GetTitleEntryText(const TitleEntry& entry, ItemColu
return wxEmptyString;
}
std::string wxTitleManagerList::GetTranslatedTitleEntryType(EntryType type)
{
switch (type)
{
case EntryType::Base:
return _("base").utf8_string();
case EntryType::Update:
return _("update").utf8_string();
case EntryType::Dlc:
return _("DLC").utf8_string();
case EntryType::Save:
return _("save").utf8_string();
case EntryType::System:
return _("system").utf8_string();
default:
return std::to_string(static_cast<std::underlying_type_t<EntryType>>(type));
}
}
void wxTitleManagerList::HandleTitleListCallback(CafeTitleListCallbackEvent* evt)
{
if (evt->eventType != CafeTitleListCallbackEvent::TYPE::TITLE_DISCOVERED &&

View file

@ -132,32 +132,9 @@ private:
bool SortFunc(int column, const Type_t& v1, const Type_t& v2);
static wxString GetTitleEntryText(const TitleEntry& entry, ItemColumn column);
static std::string GetTranslatedTitleEntryType(EntryType entryType);
std::future<bool> m_context_worker;
uint64 m_callbackIdTitleList;
uint64 m_callbackIdSaveList;
};
template <>
struct fmt::formatter<wxTitleManagerList::EntryType> : formatter<string_view>
{
using base = fmt::formatter<fmt::string_view>;
template <typename FormatContext>
auto format(const wxTitleManagerList::EntryType& type, FormatContext& ctx)
{
switch (type)
{
case wxTitleManagerList::EntryType::Base:
return base::format("base", ctx);
case wxTitleManagerList::EntryType::Update:
return base::format("update", ctx);
case wxTitleManagerList::EntryType::Dlc:
return base::format("DLC", ctx);
case wxTitleManagerList::EntryType::Save:
return base::format("save", ctx);
case wxTitleManagerList::EntryType::System:
return base::format("system", ctx);
}
return base::format(std::to_string(static_cast<std::underlying_type_t<wxTitleManagerList::EntryType>>(type)), ctx);
}
};