36#ifdef WITH_INTERNATIONAL
46#ifdef WITH_INTERNATIONAL
49static const char **locales =
nullptr;
50static int num_locales = 0;
51static EnumPropertyItem *locales_menu =
nullptr;
52static int num_locales_menu = 0;
54static void free_locales()
57 int idx = num_locales_menu - 1;
59 MEM_delete(locales_menu[idx].identifier);
60 MEM_delete(locales_menu[idx].name);
61 MEM_delete(locales_menu[idx].description);
64 MEM_SAFE_DELETE(locales_menu);
67 MEM_SAFE_DELETE(locales);
68 num_locales = num_locales_menu = 0;
71static void fill_locales()
74 if (!languages_path.has_value()) {
75 CLOG_WARN(&
LOG,
"'locale' data path for translations not found");
94 char *
str = (
char *)line->link;
100 if (t >= num_locales) {
113 if (num_locales > 0) {
116 const char *loc, *desc, *sep1, *sep2, *sep3;
118 char *
str = (
char *)line->link;
124 const int id = atoi(
str);
125 sep1 = strchr(
str,
':');
128 sep2 = strchr(sep1,
':');
130 locales_menu[idx].value =
id;
131 locales_menu[idx].icon = 0;
132 locales_menu[idx].name =
BLI_strdupn(sep1, sep2 - sep1);
135 sep3 = strchr(sep2,
':');
138 locales_menu[idx].identifier = loc =
BLI_strdupn(sep2, sep3 - sep2);
141 desc =
BLI_sprintfN(
"Locale code: %s. Translation progress: %s", loc, sep3);
144 locales_menu[idx].identifier = loc =
BLI_strdup(sep2);
150 if (loc[0] !=
'\0') {
156 "Automatically choose the system-defined language if available, or fall-back to "
162 locales_menu[idx].description = desc;
167 locales_menu[idx].description = desc;
178 locales_menu[idx].identifier =
nullptr;
179 locales_menu[idx].value = locales_menu[idx].icon = 0;
180 locales_menu[idx].name = locales_menu[idx].description =
"";
188#ifdef WITH_INTERNATIONAL
211 if (lang !=
nullptr) {
212 char *old_locale = setlocale(LC_ALL,
nullptr);
215 if (setlocale(LC_ALL, lang) ==
nullptr) {
216 setenv(
"LANG",
"C", 1);
217 CLOG_WARN(&
LOG,
"Falling back to standard locale (\"C\")");
219 setlocale(LC_ALL, old_locale);
220 MEM_delete(old_locale);
224#ifdef WITH_INTERNATIONAL
231#ifdef WITH_INTERNATIONAL
237#ifdef WITH_INTERNATIONAL
238static uint lang_from_userdef()
248#ifdef WITH_INTERNATIONAL
249# define ULANGUAGE lang_from_userdef()
250# define LOCALE(_id) (locales ? locales[(_id)] : "")
255#ifdef WITH_INTERNATIONAL
256 int ulang = ULANGUAGE;
257 std::string locale_name =
str ?
str : LOCALE(ulang);
270#ifdef WITH_INTERNATIONAL
272 const char *
locale = LOCALE(ULANGUAGE);
292 char **language_country,
293 char **language_variant)
301 if (language || language_variant) {
328 if (language_country) {
333 *language_country =
nullptr;
336 if (language_variant) {
341 *language_variant =
nullptr;
344 if (_t && !language) {
File and directory operations.
#define BLI_path_join(...)
#define CLOG_WARN(clg_ref,...)
Read Blender memory allocation and freeing.
void init(const StringRef locale_full_name, const Vector< std::string > &domains, const Vector< std::string > &paths)
void BLT_lang_set(const char *)
char * BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
struct LinkNode * BLI_file_read_as_lines(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
std::optional< std::string > BKE_appdir_folder_id(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
void BLT_lang_locale_explode(const char *locale, char **language, char **country, char **variant, char **language_country, char **language_variant)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
const char * BLT_lang_get()
const EnumPropertyItem * BLT_lang_RNA_enum_properties()
void BLI_file_free_lines(struct LinkNode *lines)
const char * BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
PipelineCompute lines(lines_main)