Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up user-facing strings to facilitate translation #158

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/libretro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ add_library(melondsds_libretro MODULE
std/chrono.hpp
std/semaphore.hpp
std/span.hpp
strings/en_us.hpp
strings/en_us/error.hpp
strings/en_us/notice.hpp
strings/en_us/osd.hpp
sram.cpp
sram.hpp
tracy.hpp
Expand Down
6 changes: 4 additions & 2 deletions src/libretro/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@
#include "std/span.hpp"
#include "tracy.hpp"
#include "pcap.hpp"
#include "strings/en_us.hpp"

#ifdef interface
#undef interface
#endif

using namespace melonDS;
using namespace MelonDsDs::strings::en_us;
using std::array;
using std::find_if;
using std::from_chars;
Expand Down Expand Up @@ -874,7 +876,7 @@ bool MelonDsDs::RegisterCoreOptions() noexcept {
}

} else {
retro::set_error_message("Failed to get system directory, anything that needs it won't work.");
retro::set_error_message(SysDirFailed);
}

if (!dsiNandPaths.empty()) {
Expand Down Expand Up @@ -1003,7 +1005,7 @@ bool MelonDsDs::RegisterCoreOptions() noexcept {
#endif

if (!retro::set_core_options(optionsUs)) {
retro::set_error_message("Failed to set core option definitions, functionality will be limited.");
retro::set_error_message(OptionInitFailed);
return false;
}

Expand Down
28 changes: 9 additions & 19 deletions src/libretro/config/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "format.hpp"
#include "retro/http.hpp"
#include "retro/info.hpp"
#include "strings/strings.hpp"
#include "types.hpp"

using std::make_optional;
Expand All @@ -59,6 +60,7 @@ namespace MelonDsDs {
const char *TMD_DIR_NAME = "tmd";
const char* SENTINEL_NAME = "melon.dat";
constexpr uint32_t RSA256_SIGNATURE_TYPE = 16777472;
using namespace strings::en_us;

static melonDS::NDSArgs GetNdsArgs(
const CoreConfig& config,
Expand Down Expand Up @@ -134,9 +136,7 @@ std::unique_ptr<melonDS::NDS> MelonDsDs::CreateConsole(
if (type == ConsoleType::DSi) {
// If we're in DSi mode...
if (gbaInfo || gbaSaveInfo) {
retro::set_warn_message(
"The DSi does not support GBA connectivity. Not loading the requested GBA ROM or SRAM."
);
retro::set_warn_message(DsiDoesntHaveGbaSlot);
}
return std::make_unique<melonDS::DSi>(GetDSiArgs(config, ndsInfo));
}
Expand Down Expand Up @@ -471,11 +471,7 @@ static std::pair<unique_ptr<uint8_t[]>, size_t> MelonDsDs::LoadGbaSram(const ret
// We don't support GBA SRAM files in archives right now;
// libretro-common has APIs for extracting and re-inserting them,
// but I just can't be bothered.
retro::set_error_message(
"melonDS DS does not support archived GBA save data right now. "
"Please extract it and try again. "
"Continuing without using the save data."
);
retro::set_error_message(ArchivedGbaSaveNotSupported);

return { nullptr, 0 };
}
Expand All @@ -492,11 +488,7 @@ static std::pair<unique_ptr<uint8_t[]>, size_t> MelonDsDs::LoadGbaSram(const ret

// We don't support rzip-compressed GBA save files right now;
// I can't be bothered.
retro::set_error_message(
"melonDS DS does not support compressed GBA save data right now. "
"Please disable save data compression in the frontend and try again. "
"Continuing without using the save data."
);
retro::set_error_message(CompressedGbaSaveNotSupported);

rzipstream_close(gba_save_file);
return { nullptr, 0 };
Expand Down Expand Up @@ -955,15 +947,13 @@ static void MelonDsDs::CustomizeFirmware(const CoreConfig& config, Firmware& fir
memset(&chk2[0x0C], 0, 8);

if (!memcmp(chk1, chk2, sizeof(chk1))) {
constexpr const char* const WARNING_MESSAGE =
"Corrupted firmware detected!\n"
"Any game that alters Wi-fi settings will break this firmware, even on real hardware.\n";


if (config.ShowBiosWarnings()) {
retro::set_warn_message(WARNING_MESSAGE);
retro::set_warn_message(HackedFirmwareWarning);
}
else {
retro::warn(WARNING_MESSAGE);
retro::warn(HackedFirmwareWarning);
}
}
}
Expand All @@ -981,7 +971,7 @@ static void MelonDsDs::CustomizeFirmware(const CoreConfig& config, Firmware& fir

optional<u16string> convertedUsername = ConvertUsername(*username);
if (!convertedUsername) {
retro::set_warn_message("Can't use the name \"{}\" on the DS, using default name instead.", *username);
retro::set_warn_message(UsernameFailed, fmt::arg("name", *username));
convertedUsername = ConvertUsername(config::values::firmware::DEFAULT_USERNAME);
}

Expand Down
13 changes: 7 additions & 6 deletions src/libretro/config/definitions/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ namespace MelonDsDs::config::definitions {
"Indirect: Use libslirp to emulate the DS's network stack. Simple and needs no setup.\n"
#ifdef HAVE_NETWORKING_DIRECT_MODE
"Direct: Routes emulated Wi-Fi packets to the host's network interface. "
"Faster and more reliable, but requires an ethernet connection and "
#ifdef _WIN32
"that WinPcap or Npcap is installed. "
#else
"that libpcap is installed. "
#endif
# ifdef _WIN32
"Faster and more reliable, but requires an ethernet connection "
"and that WinPcap or Npcap is installed. "
# else
"Faster and more reliable, but requires an ethernet connection "
"and that libpcap is installed. "
# endif
"If unavailable, falls back to Indirect mode.\n"
#endif
"\n"
Expand Down
41 changes: 13 additions & 28 deletions src/libretro/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <compat/strl.h>
#include <file/file_path.h>

#include "../strings/strings.hpp"
#include "../config/console.hpp"
#include "../exceptions.hpp"
#include "../format.hpp"
Expand All @@ -44,16 +45,10 @@

using std::span;
using namespace melonDS::DSi_NAND;
using namespace MelonDsDs::strings::en_us;

constexpr size_t DS_MEMORY_SIZE = 0x400000;
constexpr size_t DSI_MEMORY_SIZE = 0x1000000;
static const char* const INTERNAL_ERROR_MESSAGE =
"An internal error occurred with melonDS DS. "
"Please contact the developer with the log file.";

static const char* const UNKNOWN_ERROR_MESSAGE =
"An unknown error has occurred with melonDS DS. "
"Please contact the developer with the log file.";

date::local_seconds LocalTime() noexcept {
using namespace std::chrono;
Expand Down Expand Up @@ -189,7 +184,7 @@ void MelonDsDs::CoreState::Reset() {
ZoneScopedN(TracyFunction);

if (_messageScreen) {
retro::set_error_message("Please follow the advice on this screen, then unload/reload the core.");
retro::set_error_message(PleaseResetCore);
return;
// TODO: Allow the game to be reset from the error screen
// (gotta reinitialize the DS here)
Expand Down Expand Up @@ -290,7 +285,7 @@ bool MelonDsDs::CoreState::RunDeferredInitialization() noexcept {
}
catch (...) {
retro::error("Deferred initialization failed; exiting core");
retro::set_error_message(UNKNOWN_ERROR_MESSAGE);
retro::set_error_message(UnknownError);
return false;
}

Expand Down Expand Up @@ -430,9 +425,6 @@ void MelonDsDs::CoreState::InitFlushFirmwareTask() noexcept
_flushTaskId = flushTask.Identifier();
retro::task::push(std::move(flushTask));
}
else {
retro::set_error_message("System path not found, changes to firmware settings won't be saved.");
}
}

void MelonDsDs::CoreState::ResetRenderState() {
Expand All @@ -450,8 +442,7 @@ bool MelonDsDs::CoreState::LoadGame(unsigned type, std::span<const retro_game_in

// ...then load the game.
if (!retro::set_pixel_format(RETRO_PIXEL_FORMAT_XRGB8888)) {
throw environment_exception(
"Failed to set the required XRGB8888 pixel format for rendering; it may not be supported.");
throw environment_exception(PixelFormatUnsupported);
}

if (RegisterCoreOptions()) {
Expand Down Expand Up @@ -528,11 +519,11 @@ catch (const emulator_exception& e) {
}
catch (const std::exception& e) {
retro::error("{}", e.what());
retro::set_error_message(INTERNAL_ERROR_MESSAGE);
retro::set_error_message(InternalError);
return false;
}
catch (...) {
retro::set_error_message(UNKNOWN_ERROR_MESSAGE);
retro::set_error_message(UnknownError);
return false;
}

Expand Down Expand Up @@ -610,7 +601,7 @@ void MelonDsDs::CoreState::ApplyConfig(const CoreConfig& config) noexcept {
// (so that excessive warnings aren't shown)
if (!_micState.IsMicInterfaceAvailable() && config.ShowUnsupportedFeatureWarnings()) {
// ...but this frontend doesn't support it...
retro::set_warn_message("This frontend doesn't support microphones.");
retro::set_warn_message(MicNotSupported);
}
else if (!_micState.IsHostMicOpen()) {
retro::warn("Failed to open host microphone");
Expand Down Expand Up @@ -660,7 +651,6 @@ void MelonDsDs::CoreState::InitContent(unsigned type, std::span<const retro_game
break;
default:
retro::error("Unknown game type {}", type);
retro::set_error_message(INTERNAL_ERROR_MESSAGE);
throw std::runtime_error("Unknown game type");
}
}
Expand Down Expand Up @@ -799,24 +789,19 @@ bool MelonDsDs::CoreState::Unserialize(std::span<const std::byte> data) noexcept

if (major < SAVESTATE_MAJOR) {
// If this savestate is too old...
retro::set_error_message(
"This savestate is too old, can't load it.\n"
"Save your game normally in the older version and import the save data.");
retro::set_error_message(StateTooOld);
}
else if (major > SAVESTATE_MAJOR) {
// If this savestate is too new...
retro::set_error_message(
"This savestate is too new, can't load it.\n"
"Save your game normally in the newer version, "
"then update this core or import the save data.");
retro::set_error_message(StateTooNew);
}

return false;
}

if (data.size() != *_savestateSize) {
retro::error("Expected a {}-byte savestate, got one of {} bytes", *_savestateSize, data.size());
retro::set_error_message("Can't load this savestate, most likely the ROM or the core is wrong.");
retro::set_error_message(StateLoadFailed);
return false;
}

Expand Down Expand Up @@ -875,13 +860,13 @@ void MelonDsDs::CoreState::CheatSet(unsigned index, bool enabled, std::string_vi
return;

if (!enabled) {
retro::set_warn_message("Action Replay codes can't be undone, restart the game to remove their effects.");
retro::set_warn_message(CantDisableCheat);
return;
}

if (!regex_match(code.data(), _cheatSyntax)) {
// If we're trying to activate this cheat code, but it's not valid...
retro::set_warn_message("Cheat #{} ({:.8}...) isn't valid, ignoring it.", index, code);
retro::set_warn_message(InvalidCheat, fmt::arg("index", index), fmt::arg("code", code));
return;
}

Expand Down
14 changes: 8 additions & 6 deletions src/libretro/core/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
#include "microphone.hpp"
#include "retro/task_queue.hpp"
#include "tracy.hpp"
#include "strings/en_us.hpp"

using namespace melonDS;
using namespace MelonDsDs::strings::en_us;

using std::nullopt;
using std::optional;
Expand Down Expand Up @@ -338,18 +340,18 @@ retro::task::TaskSpec MelonDsDs::CoreState::OnScreenDisplayTask() noexcept {
if (Config.ShowCurrentLayout()) {
fmt::format_to(
inserter,
"{}Layout {}/{}",
buf.size() == 0 ? "" : OSD_DELIMITER,
_screenLayout.LayoutIndex() + 1,
_screenLayout.NumberOfLayouts()
CurrentLayout,
fmt::arg("sep", buf.size() == 0 ? "" : OSD_DELIMITER),
fmt::arg("layout_num", _screenLayout.LayoutIndex() + 1),
fmt::arg("num_layouts", _screenLayout.NumberOfLayouts())
);
}

if (Config.ShowLidState() && nds.IsLidClosed()) {
fmt::format_to(
inserter,
"{}Closed",
buf.size() == 0 ? "" : OSD_DELIMITER
ScreenState,
fmt::arg("sep", buf.size() == 0 ? "" : OSD_DELIMITER)
);
}

Expand Down
Loading
Loading