Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenfont/intern/blf_lang.c')
-rw-r--r--source/blender/blenfont/intern/blf_lang.c127
1 files changed, 88 insertions, 39 deletions
diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c
index 9086799f984..73294f1aed6 100644
--- a/source/blender/blenfont/intern/blf_lang.c
+++ b/source/blender/blenfont/intern/blf_lang.c
@@ -27,41 +27,35 @@
* \ingroup blf
*/
-
-#include "BLF_translation.h" /* own include */
-
-#include "BLI_utildefines.h"
-
-#ifdef WITH_INTERNATIONAL
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "boost_locale_wrapper.h"
-
-#include "BKE_global.h"
-
-#include "DNA_userdef_types.h"
-
#include "RNA_types.h"
-#include "MEM_guardedalloc.h"
+#include "BLF_translation.h" /* own include */
#include "BLI_fileops.h"
#include "BLI_linklist.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
+#include "BKE_global.h"
+
+#include "DNA_userdef_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#ifdef WITH_INTERNATIONAL
+
+#include "boost_locale_wrapper.h"
+
/* Locale options. */
static const char **locales = NULL;
static int num_locales = 0;
static EnumPropertyItem *locales_menu = NULL;
static int num_locales_menu = 0;
-#define ULANGUAGE ((U.language >= 0 && U.language < num_locales) ? U.language : 0)
-#define LOCALE(_id) (locales ? locales[_id] : "")
-
static void free_locales(void)
{
if (locales) {
@@ -113,7 +107,7 @@ static void fill_locales(void)
}
num_locales_menu++; /* The "closing" void item... */
- /* And now, buil locales and locale_menu! */
+ /* And now, build locales and locale_menu! */
locales_menu = MEM_callocN(num_locales_menu * sizeof(EnumPropertyItem), __func__);
line = lines;
/* Do not allocate locales with zero-sized mem, as LOCALE macro uses NULL locales as invalid marker! */
@@ -177,14 +171,20 @@ static void fill_locales(void)
BLI_file_free_lines(lines);
}
+#endif /* WITH_INTERNATIONAL */
EnumPropertyItem *BLF_RNA_lang_enum_properties(void)
{
+#ifdef WITH_INTERNATIONAL
return locales_menu;
+#else
+ return NULL;
+#endif
}
void BLF_lang_init(void)
{
+#ifdef WITH_INTERNATIONAL
char *messagepath = BLI_get_folder(BLENDER_DATAFILES, "locale");
if (messagepath) {
@@ -194,15 +194,24 @@ void BLF_lang_init(void)
else {
printf("%s: 'locale' data path for translations not found, continuing\n", __func__);
}
+#else
+#endif
}
void BLF_lang_free(void)
{
+#ifdef WITH_INTERNATIONAL
free_locales();
+#else
+#endif
}
+#define ULANGUAGE ((U.language >= 0 && U.language < num_locales) ? U.language : 0)
+#define LOCALE(_id) (locales ? locales[(_id)] : "")
+
void BLF_lang_set(const char *str)
{
+#ifdef WITH_INTERNATIONAL
int ulang = ULANGUAGE;
const char *short_locale = str ? str : LOCALE(ulang);
const char *short_locale_utf8 = NULL;
@@ -232,37 +241,77 @@ void BLF_lang_set(const char *str)
if (short_locale[0]) {
MEM_freeN((void *)short_locale_utf8);
}
+#else
+ (void)str;
+#endif
}
+/* Get the current locale (short code, e.g. es_ES). */
const char *BLF_lang_get(void)
{
- int uilang = ULANGUAGE;
- return LOCALE(uilang);
+#ifdef WITH_INTERNATIONAL
+ const char *locale = LOCALE(ULANGUAGE);
+ if (locale[0] == '\0') {
+ /* Default locale, we have to find which one we are actually using! */
+ locale = bl_locale_get();
+ }
+ return locale;
+#else
+ return "";
+#endif
}
#undef LOCALE
#undef ULANGUAGE
-#else /* ! WITH_INTERNATIONAL */
-
-void BLF_lang_init(void)
-{
- return;
-}
-
-void BLF_lang_free(void)
+/* Get locale's elements (if relevant pointer is not NULL and element actually exists, e.g. if there is no variant,
+ * *variant and *language_variant will always be NULL).
+ * Non-null elements are always MEM_mallocN'ed, it's the caller's responsibility to free them.
+ * NOTE: Keep that one always available, you never know, may become useful even in no-WITH_INTERNATIONAL context...
+ */
+void BLF_locale_explode(const char *locale, char **language, char **country, char **variant,
+ char **language_country, char **language_variant)
{
- return;
-}
+ char *m1, *m2, *_t = NULL;
-void BLF_lang_set(const char *UNUSED(str))
-{
- return;
-}
+ m1 = strchr(locale, '_');
+ m2 = strchr(locale, '@');
-const char *BLF_lang_get(void)
-{
- return "";
+ if (language || language_variant) {
+ if (m1 || m2) {
+ _t = m1 ? BLI_strdupn(locale, m1 - locale) : BLI_strdupn(locale, m2 - locale);
+ if (language)
+ *language = _t;
+ }
+ else if (language) {
+ *language = BLI_strdup(locale);
+ }
+ }
+ if (country) {
+ if (m1)
+ *country = m2 ? BLI_strdupn(m1 + 1, m2 - (m1 + 1)) : BLI_strdup(m1 + 1);
+ else
+ *country = NULL;
+ }
+ if (variant) {
+ if (m2)
+ *variant = BLI_strdup(m2 + 1);
+ else
+ *variant = NULL;
+ }
+ if (language_country) {
+ if (m1)
+ *language_country = m2 ? BLI_strdupn(locale, m2 - locale) : BLI_strdup(locale);
+ else
+ *language_country = NULL;
+ }
+ if (language_variant) {
+ if (m2)
+ *language_variant = m1 ? BLI_strdupcat(_t, m2) : BLI_strdup(locale);
+ else
+ *language_variant = NULL;
+ }
+ if (_t && !language) {
+ MEM_freeN(_t);
+ }
}
-
-#endif /* WITH_INTERNATIONAL */