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

Adding localization support to cheevos.c #15739

Open
wants to merge 2 commits into
base: master
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
58 changes: 34 additions & 24 deletions cheevos/cheevos.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's reasonable to localize this as rc_error_str will still return an English error message.

Expand Down Expand Up @@ -1157,17 +1156,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 @@ -1466,7 +1466,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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about rc_error_str.

Expand Down Expand Up @@ -1840,10 +1839,9 @@ 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",
rc_console_name(console_id), sysinfo->library_name);
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 @@ -2701,31 +2699,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 @@ -3123,9 +3134,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 @@ -14309,6 +14309,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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enum for this should be more specific. Maybe MSG_CHEEVOS_HARDCORE_PAUSED_INVALID_CORE?

There are several other reasons hardcore could be disabled in rcheevos_validate_config_settings.

)
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"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably better to include the placeholder ("Playing %s") and change the string building to use snprintf. String concatenation is generally frowned upon for localization.

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 @@ -479,6 +479,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
Loading