Android: use proper system locale definition
parent
aa5a25494e
commit
7918471ad2
|
@ -566,18 +566,11 @@ void set_default_settings(Settings *settings) {
|
|||
#endif // iOS
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__) || defined(__APPLE__)
|
||||
char lang[3] = {0};
|
||||
|
||||
#ifdef __ANDROID__
|
||||
// Auto-detect language on Android
|
||||
AConfiguration_getLanguage(porting::app_global->config, lang);
|
||||
#else
|
||||
#if defined(__APPLE__)
|
||||
// Auto-detect language on iOS / macOS
|
||||
char lang[3] = {0};
|
||||
NSString *syslang = [[NSLocale preferredLanguages] firstObject];
|
||||
[syslang getBytes:lang maxLength:2 usedLength:nil encoding:NSASCIIStringEncoding options:0 range:NSMakeRange(0, 2) remainingRange:nil];
|
||||
#endif
|
||||
|
||||
settings->setDefault("language", lang);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -18,12 +18,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
*/
|
||||
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include "gettext.h"
|
||||
#include "util/string.h"
|
||||
#include "log.h"
|
||||
#include "porting.h"
|
||||
|
||||
#if USE_GETTEXT && defined(_MSC_VER)
|
||||
#include <windows.h>
|
||||
|
@ -127,6 +128,10 @@ void init_gettext(const char *path, const std::string &configured_language,
|
|||
// Add user specified locale to environment
|
||||
setenv("LANGUAGE", configured_language.c_str(), 1);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
setenv("LANG", configured_language.c_str(), 1);
|
||||
#endif
|
||||
|
||||
// Reload locale with changed environment
|
||||
setlocale(LC_ALL, "");
|
||||
#elif defined(_MSC_VER)
|
||||
|
@ -203,6 +208,11 @@ void init_gettext(const char *path, const std::string &configured_language,
|
|||
}
|
||||
else {
|
||||
/* set current system default locale */
|
||||
#ifdef __ANDROID__
|
||||
char lang[3] = {0};
|
||||
AConfiguration_getLanguage(porting::app_global->config, lang);
|
||||
setenv("LANG", lang, 1);
|
||||
#endif
|
||||
setlocale(LC_ALL, "");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue