Skip to content

Commit

Permalink
Adding localization support to cheevos.c
Browse files Browse the repository at this point in the history
  • Loading branch information
toadkarter committed Sep 26, 2023
1 parent 9d67cc9 commit fd9960f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 23 deletions.
56 changes: 33 additions & 23 deletions cheevos/cheevos.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ static void rcheevos_activate_achievements(void)
{
char buffer[256];
buffer[0] = '\0';
/* TODO/FIXME - localize */
snprintf(buffer, sizeof(buffer),
"Could not activate achievement %u \"%s\": %s",
achievement->id, achievement->title, rc_error_str(result));
Expand Down Expand Up @@ -682,17 +681,18 @@ int rcheevos_get_richpresence(char *s, size_t len)

if (ret <= 0 && rcheevos_locals.game.title)
{
/* TODO/FIXME - localize */
size_t _len = strlcpy(s, "Playing ", len);
strlcpy(s + _len, rcheevos_locals.game.title, len - _len);
int _len = snprintf(s, len, msg_hash_to_str(MSG_CHEEVOS_RICH_PRESENCE_PLAYING),
rcheevos_locals.game.title);

if (_len < 0)
return -1;
}
return ret;
}
if (rcheevos_locals.game.title)
{
/* TODO/FIXME - localize */
size_t _len = strlcpy(s, "Spectating ", len);
return (int)strlcpy(s + _len, rcheevos_locals.game.title, len - _len);
return snprintf(s, len, msg_hash_to_str(MSG_CHEEVOS_RICH_PRESENCE_SPECTATING),
rcheevos_locals.game.title);
}
return 0;
}
Expand Down Expand Up @@ -936,7 +936,6 @@ static void rcheevos_activate_leaderboards(void)
{
char buffer[256];
buffer[0] = '\0';
/* TODO/FIXME - localize */
snprintf(buffer, sizeof(buffer),
"Could not activate leaderboard %u \"%s\": %s",
leaderboard->id, leaderboard->title, rc_error_str(result));
Expand Down Expand Up @@ -1229,9 +1228,8 @@ void rcheevos_validate_config_settings(void)
{
char buffer[256];
buffer[0] = '\0';
/* TODO/FIXME - localize */
snprintf(buffer, sizeof(buffer),
"Hardcore paused. You cannot earn hardcore achievements for %s using %s",
msg_hash_to_str(MSG_CHEEVOS_HARDCORE_PAUSED_INVALID_CORE),
rc_console_name(rcheevos_locals.game.console_id), sysinfo->library_name);
CHEEVOS_LOG(RCHEEVOS_TAG "%s\n", buffer);
rcheevos_pause_hardcore();
Expand Down Expand Up @@ -1742,31 +1740,44 @@ static void rcheevos_show_game_placard(void)
number_of_active++;
}

/* TODO/FIXME - localize strings */
if (number_of_core == 0)
strlcpy(msg, "This game has no achievements.", sizeof(msg));
strlcpy(msg, msg_hash_to_str(MSG_CHEEVOS_GAME_HAS_NO_ACHIEVEMENTS), sizeof(msg));
else if (!number_of_unsupported)
{
if (settings->bools.cheevos_start_active)
snprintf(msg, sizeof(msg),
"All %d achievements activated for this session.",
msg_hash_to_str(MSG_CHEEVOS_ALL_ACHIEVEMENTS_ACTIVATED),
number_of_core);
else
snprintf(msg, sizeof(msg),
"You have %d of %d achievements unlocked.",
msg_hash_to_str(MSG_CHEEVOS_NUMBER_ACHIEVEMENTS_UNLOCKED),
number_of_core - number_of_active, number_of_core);
}
else
{
char number_of_unsupported_msg[64];
int _len;

snprintf(number_of_unsupported_msg,
sizeof(number_of_unsupported_msg),
msg_hash_to_str(MSG_CHEEVOS_UNSUPPORTED_COUNT),
number_of_unsupported);

if (settings->bools.cheevos_start_active)
snprintf(msg, sizeof(msg),
"All %d achievements activated for this session (%d unsupported).",
number_of_core, number_of_unsupported);
_len = snprintf(msg, sizeof(msg),
msg_hash_to_str(MSG_CHEEVOS_ALL_ACHIEVEMENTS_ACTIVATED),
number_of_core);
else
snprintf(msg, sizeof(msg),
"You have %d of %d achievements unlocked (%d unsupported).",
number_of_core - number_of_active - number_of_unsupported,
number_of_core, number_of_unsupported);
_len = snprintf(msg, sizeof(msg),
msg_hash_to_str(MSG_CHEEVOS_NUMBER_ACHIEVEMENTS_UNLOCKED),
number_of_core - number_of_active - number_of_unsupported,
number_of_core);

_len += snprintf(msg + _len, sizeof(msg) - _len,
" (%s)", number_of_unsupported_msg);

if (_len < 0)
return;
}

msg[sizeof(msg) - 1] = 0;
Expand Down Expand Up @@ -2164,9 +2175,8 @@ static void rcheevos_login_callback(void* userdata)
{
char msg[256];
msg[0] = '\0';
/* TODO/FIXME - localize */
snprintf(msg, sizeof(msg),
"RetroAchievements: Logged in as \"%s\".",
msg_hash_to_str(MSG_CHEEVOS_LOGGED_IN_AS_USER),
rcheevos_locals.displayname);
runloop_msg_queue_push(msg, 0, 2 * 60, false, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
Expand Down
32 changes: 32 additions & 0 deletions intl/msg_hash_us.h
Original file line number Diff line number Diff line change
Expand Up @@ -13668,6 +13668,38 @@ MSG_HASH(
MSG_CHEEVOS_HARDCORE_MODE_ENABLE,
"Achievements Hardcore Mode Enabled, save state & rewind were disabled."
)
MSG_HASH(
MSG_CHEEVOS_HARDCORE_PAUSED_INVALID_CORE,
"Hardcore paused. You cannot earn hardcore achievements for %s using %s"
)
MSG_HASH(
MSG_CHEEVOS_LOGGED_IN_AS_USER,
"RetroAchievements: Logged in as \"%s\"."
)
MSG_HASH(
MSG_CHEEVOS_GAME_HAS_NO_ACHIEVEMENTS,
"This game has no achievements."
)
MSG_HASH(
MSG_CHEEVOS_ALL_ACHIEVEMENTS_ACTIVATED,
"All %d achievements activated for this session"
)
MSG_HASH(
MSG_CHEEVOS_NUMBER_ACHIEVEMENTS_UNLOCKED,
"You have %d of %d achievements unlocked"
)
MSG_HASH(
MSG_CHEEVOS_UNSUPPORTED_COUNT,
"%d unsupported"
)
MSG_HASH(
MSG_CHEEVOS_RICH_PRESENCE_PLAYING,
"Playing %s"
)
MSG_HASH(
MSG_CHEEVOS_RICH_PRESENCE_SPECTATING,
"Spectating %s"
)
MSG_HASH(
MSG_COMPARING_WITH_KNOWN_MAGIC_NUMBERS,
"Comparing with known magic numbers..."
Expand Down
8 changes: 8 additions & 0 deletions msg_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,14 @@ enum msg_hash_enums
MSG_REWIND_REACHED_END,
MSG_FAILED_TO_START_MOVIE_RECORD,
MSG_CHEEVOS_HARDCORE_MODE_ENABLE,
MSG_CHEEVOS_HARDCORE_PAUSED_INVALID_CORE,
MSG_CHEEVOS_LOGGED_IN_AS_USER,
MSG_CHEEVOS_GAME_HAS_NO_ACHIEVEMENTS,
MSG_CHEEVOS_ALL_ACHIEVEMENTS_ACTIVATED,
MSG_CHEEVOS_NUMBER_ACHIEVEMENTS_UNLOCKED,
MSG_CHEEVOS_UNSUPPORTED_COUNT,
MSG_CHEEVOS_RICH_PRESENCE_PLAYING,
MSG_CHEEVOS_RICH_PRESENCE_SPECTATING,
MSG_STATE_SLOT,
MSG_REPLAY_SLOT,
MSG_STARTING_MOVIE_RECORD_TO,
Expand Down

0 comments on commit fd9960f

Please sign in to comment.