set default language on first startup according to OS setting (initial *nix implementation)

This commit is contained in:
Brad Parker 2019-04-15 23:14:49 -04:00
parent 1baebdbd47
commit aa588dec35
23 changed files with 97 additions and 4 deletions

View File

@ -1754,7 +1754,7 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings,
SETTING_UINT("netplay_share_analog", &settings->uints.netplay_share_analog, true, netplay_share_analog, false);
#endif
#ifdef HAVE_LANGEXTRA
SETTING_UINT("user_language", msg_hash_get_uint(MSG_HASH_USER_LANGUAGE), true, RETRO_LANGUAGE_ENGLISH, false);
SETTING_UINT("user_language", msg_hash_get_uint(MSG_HASH_USER_LANGUAGE), true, def_user_language, false);
#endif
SETTING_UINT("bundle_assets_extract_version_current", &settings->uints.bundle_assets_extract_version_current, true, 0, false);
SETTING_UINT("bundle_assets_extract_last_version", &settings->uints.bundle_assets_extract_last_version, true, 0, false);
@ -3281,6 +3281,9 @@ static bool config_load_file(const char *path, bool set_defaults,
frontend_driver_set_sustained_performance_mode(settings->bools.sustained_performance_mode);
recording_driver_update_streaming_url();
if (!config_entry_exists(conf, "user_language"))
msg_hash_set_uint(MSG_HASH_USER_LANGUAGE, frontend_driver_get_user_language());
ret = true;
end:
if (conf)

View File

@ -604,5 +604,6 @@ frontend_ctx_driver_t frontend_ctx_ctr =
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"ctr",
};

View File

@ -773,10 +773,11 @@ frontend_ctx_driver_t frontend_ctx_darwin = {
NULL, /* watch_path_for_changes */
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
#if (defined(OSX) && !(defined(__ppc__) || defined(__ppc64__)))
#if (defined(OSX) && !(defined(__ppc__) || defined(__ppc64__)))
frontend_darwin_get_cpu_model_name,
#else
#else
NULL,
#endif
#endif
NULL, /* get_user_language */
"darwin",
};

View File

@ -72,5 +72,6 @@ frontend_ctx_driver_t frontend_ctx_dos = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"dos",
};

View File

@ -267,5 +267,6 @@ frontend_ctx_driver_t frontend_ctx_emscripten = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"emscripten"
};

View File

@ -548,5 +548,6 @@ frontend_ctx_driver_t frontend_ctx_gx = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"gx",
};

View File

@ -48,5 +48,6 @@ frontend_ctx_driver_t frontend_ctx_null = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"null",
};

View File

@ -369,5 +369,6 @@ frontend_ctx_driver_t frontend_ctx_orbis = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"orbis",
};

View File

@ -415,5 +415,6 @@ frontend_ctx_driver_t frontend_ctx_ps2 = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"null",
};

View File

@ -639,5 +639,6 @@ frontend_ctx_driver_t frontend_ctx_ps3 = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"ps3",
};

View File

@ -534,6 +534,7 @@ frontend_ctx_driver_t frontend_ctx_psp = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
#ifdef VITA
"vita",
#else

View File

@ -208,5 +208,6 @@ frontend_ctx_driver_t frontend_ctx_qnx = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"qnx",
};

View File

@ -945,5 +945,6 @@ frontend_ctx_driver_t frontend_ctx_switch =
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"switch",
};

View File

@ -2494,6 +2494,15 @@ static const char* frontend_unix_get_cpu_model_name(void)
#endif
}
enum retro_language frontend_unix_get_user_language(void)
{
#ifdef ANDROID
return RETRO_LANGUAGE_ENGLISH;
#else
return rarch_get_language_from_iso(getenv("LANG"));
#endif
}
frontend_ctx_driver_t frontend_ctx_unix = {
frontend_unix_get_env, /* environment_get */
frontend_unix_init, /* init */
@ -2539,6 +2548,7 @@ frontend_ctx_driver_t frontend_ctx_unix = {
frontend_unix_check_for_path_changes,
frontend_unix_set_sustained_performance_mode,
frontend_unix_get_cpu_model_name,
frontend_unix_get_user_language,
#ifdef ANDROID
"android"
#else

View File

@ -447,5 +447,6 @@ frontend_ctx_driver_t frontend_ctx_uwp = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"uwp"
};

View File

@ -302,6 +302,7 @@ frontend_ctx_driver_t frontend_ctx_wiiu =
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"wiiu",
NULL, /* get_video_driver */
};

View File

@ -603,5 +603,6 @@ frontend_ctx_driver_t frontend_ctx_win32 = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
frontend_win32_get_cpu_model_name,
NULL, /* get_user_language */
"win32"
};

View File

@ -434,5 +434,6 @@ frontend_ctx_driver_t frontend_ctx_xdk = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"xdk",
};

View File

@ -95,5 +95,6 @@ frontend_ctx_driver_t frontend_ctx_qnx = {
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
"xenon",
};

View File

@ -18,6 +18,7 @@
#include <compat/strl.h>
#include <string/stdstring.h>
#include <libretro.h>
#if defined(_3DS)
#include <3ds.h>
@ -464,4 +465,12 @@ const char* frontend_driver_get_cpu_model_name(void)
return NULL;
return frontend->get_cpu_model_name();
}
enum retro_language frontend_driver_get_user_language(void)
{
frontend_ctx_driver_t *frontend = frontend_get_ptr();
if (!frontend || !frontend->get_user_language)
return RETRO_LANGUAGE_ENGLISH;
return frontend->get_user_language();
}
#endif

View File

@ -107,6 +107,7 @@ typedef struct frontend_ctx_driver
bool (*check_for_path_changes)(path_change_data_t *change_data);
void (*set_sustained_performance_mode)(bool on);
const char* (*get_cpu_model_name)(void);
enum retro_language (*get_user_language)(void);
const char *ident;
@ -214,6 +215,8 @@ void frontend_driver_set_sustained_performance_mode(bool on);
const char* frontend_driver_get_cpu_model_name(void);
enum retro_language frontend_driver_get_user_language(void);
RETRO_END_DECLS
#endif

View File

@ -5415,3 +5415,52 @@ void rarch_log_file_deinit(void)
retro_main_log_file_init(NULL, false);
}
}
enum retro_language rarch_get_language_from_iso(const char *iso639)
{
unsigned i;
enum retro_language lang = RETRO_LANGUAGE_ENGLISH;
struct lang_pair
{
const char *iso639;
enum retro_language lang;
};
const struct lang_pair pairs[] =
{
{"en", RETRO_LANGUAGE_ENGLISH},
{"ja", RETRO_LANGUAGE_JAPANESE},
{"fr", RETRO_LANGUAGE_FRENCH},
{"es", RETRO_LANGUAGE_SPANISH},
{"de", RETRO_LANGUAGE_GERMAN},
{"it", RETRO_LANGUAGE_ITALIAN},
{"nl", RETRO_LANGUAGE_DUTCH},
{"pt_BR", RETRO_LANGUAGE_PORTUGUESE_BRAZIL},
{"pt_PT", RETRO_LANGUAGE_PORTUGUESE_PORTUGAL},
{"pt", RETRO_LANGUAGE_PORTUGUESE_PORTUGAL},
{"ru", RETRO_LANGUAGE_RUSSIAN},
{"ko", RETRO_LANGUAGE_KOREAN},
{"zh_CN", RETRO_LANGUAGE_CHINESE_SIMPLIFIED},
{"zh_SG", RETRO_LANGUAGE_CHINESE_SIMPLIFIED},
{"zh_HK", RETRO_LANGUAGE_CHINESE_TRADITIONAL},
{"zh_TW", RETRO_LANGUAGE_CHINESE_TRADITIONAL},
{"zh", RETRO_LANGUAGE_CHINESE_SIMPLIFIED},
{"eo", RETRO_LANGUAGE_ESPERANTO},
{"pl", RETRO_LANGUAGE_POLISH},
{"vi", RETRO_LANGUAGE_VIETNAMESE},
{"ar", RETRO_LANGUAGE_ARABIC},
{"el", RETRO_LANGUAGE_GREEK},
};
for (i = 0; i < sizeof(pairs) / sizeof(pairs[0]); i++)
{
if (strcasestr(iso639, pairs[i].iso639))
{
lang = pairs[i].lang;
break;
}
}
return lang;
}

View File

@ -432,6 +432,8 @@ void rarch_log_file_init(void);
void rarch_log_file_deinit(void);
enum retro_language rarch_get_language_from_iso(const char *lang);
RETRO_END_DECLS
#endif