36#ifdef WITH_INTERNATIONAL
44static const char **locales =
nullptr;
45static int num_locales = 0;
47static int num_locales_menu = 0;
49static void free_locales()
52 int idx = num_locales_menu - 1;
54 MEM_freeN((
void *)locales_menu[idx].identifier);
55 MEM_freeN((
void *)locales_menu[idx].name);
56 MEM_freeN((
void *)locales_menu[idx].description);
63 num_locales = num_locales_menu = 0;
66static void fill_locales()
70 LinkNode *lines =
nullptr, *line =
nullptr;
76 if (languages_path.has_value()) {
87 str = (
char *)line->link;
93 if (t >= num_locales) {
107 if (num_locales > 0) {
108 locales =
static_cast<const char **
>(
MEM_callocN(num_locales *
sizeof(
char *), __func__));
110 const char *loc, *sep1, *sep2, *sep3;
118 const int id = atoi(
str);
119 sep1 = strchr(
str,
':');
122 sep2 = strchr(sep1,
':');
124 locales_menu[idx].
value = id;
125 locales_menu[idx].
icon = 0;
129 sep3 = strchr(sep2,
':');
145 "Automatically choose system's defined language "
146 "if available, or fall-back to English");
166 locales_menu[idx].
value = locales_menu[idx].
icon = 0;
175#ifdef WITH_INTERNATIONAL
184#ifdef WITH_INTERNATIONAL
202 if (lang !=
nullptr) {
203 char *old_locale = setlocale(LC_ALL,
nullptr);
206 if (setlocale(LC_ALL, lang) ==
nullptr) {
207 setenv(
"LANG",
"C", 1);
208 printf(
"Warning: Falling back to the standard locale (\"C\")\n");
210 setlocale(LC_ALL, old_locale);
215#ifdef WITH_INTERNATIONAL
216 if (messagepath.has_value()) {
221 printf(
"%s: 'locale' data path for translations not found, continuing\n", __func__);
229#ifdef WITH_INTERNATIONAL
235#ifdef WITH_INTERNATIONAL
236static uint lang_from_userdef()
246#ifdef WITH_INTERNATIONAL
247# define ULANGUAGE lang_from_userdef()
248# define LOCALE(_id) (locales ? locales[(_id)] : "")
253#ifdef WITH_INTERNATIONAL
254 int ulang = ULANGUAGE;
255 const char *short_locale =
str ?
str : LOCALE(ulang);
256 const char *short_locale_utf8 =
nullptr;
259 if (short_locale[0]) {
261 const char *variant = strchr(short_locale,
'@');
263 char *locale =
BLI_strdupn(short_locale, variant - short_locale);
264 short_locale_utf8 =
BLI_sprintfN(
"%s.UTF-8%s", locale, variant);
268 short_locale_utf8 =
BLI_sprintfN(
"%s.UTF-8", short_locale);
283#ifdef WITH_INTERNATIONAL
285 const char *locale = LOCALE(ULANGUAGE);
286 if (locale[0] ==
'\0') {
305 char **language_country,
306 char **language_variant)
311 m1 = strchr(locale,
'_');
312 m2 = strchr(locale,
'@');
314 if (language || language_variant) {
341 if (language_country) {
346 *language_country =
nullptr;
349 if (language_variant) {
354 *language_variant =
nullptr;
357 if (_t && !language) {
std::optional< std::string > BKE_appdir_folder_id(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
File and directory operations.
struct LinkNode * BLI_file_read_as_lines(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BLI_file_free_lines(struct LinkNode *lines)
#define BLI_path_join(...)
const char * BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
char * BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int char char int int int int size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Read Guarded memory(de)allocation.
void BLT_lang_locale_explode(const char *locale, char **language, char **country, char **variant, char **language_country, char **language_variant)
const char * BLT_lang_get()
const EnumPropertyItem * BLT_lang_RNA_enum_properties()
void BLT_lang_set(const char *str)
const char * bl_locale_get(void)
void bl_locale_set(const char *locale)
void bl_locale_init(const char *_messages_path, const char *_default_domain)
void MEM_freeN(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)