[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53945] trunk/blender/source/blender/ blenfont: Various cleanup in i18n code ( having funcs implemented in two different places is tricky, you quickly forget to add/edit one, we already have this problem with ugly bplayer stub...

Bastien Montagne montagne29 at wanadoo.fr
Mon Jan 21 09:08:24 CET 2013


Revision: 53945
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53945
Author:   mont29
Date:     2013-01-21 08:08:20 +0000 (Mon, 21 Jan 2013)
Log Message:
-----------
Various cleanup in i18n code (having funcs implemented in two different places is tricky, you quickly forget to add/edit one, we already have this problem with ugly bplayer stub... e.g. since r53938, BLF_locale_explode was not implemented in non-WITH_INTERNATIONAL builds). Also tried to simplify #ifdef's here...

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53938

Modified Paths:
--------------
    trunk/blender/source/blender/blenfont/BLF_translation.h
    trunk/blender/source/blender/blenfont/intern/blf_lang.c
    trunk/blender/source/blender/blenfont/intern/blf_translation.c

Modified: trunk/blender/source/blender/blenfont/BLF_translation.h
===================================================================
--- trunk/blender/source/blender/blenfont/BLF_translation.h	2013-01-21 06:32:09 UTC (rev 53944)
+++ trunk/blender/source/blender/blenfont/BLF_translation.h	2013-01-21 08:08:20 UTC (rev 53945)
@@ -33,6 +33,8 @@
 #ifndef __BLF_TRANSLATION_H__
 #define __BLF_TRANSLATION_H__
 
+#include "BLI_utildefines.h"  /* for bool type */
+
 #define TEXT_DOMAIN_NAME "blender"
 
 /* blf_lang.c */
@@ -53,7 +55,8 @@
 
 /* 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. 
+ * Non-null elements are always MEM_mallocN'ed, it's the caller's responsibility to free them.
+ * NOTE: Always available, even in non-WITH_INTERNATIONAL builds.
  */
 void BLF_locale_explode(const char *locale, char **language, char **country, char **variant,
                         char **language_country, char **language_variant);
@@ -63,16 +66,14 @@
 
 /* blf_translation.c  */
 
-#ifdef WITH_INTERNATIONAL
 unsigned char *BLF_get_unifont(int *unifont_size);
 void BLF_free_unifont(void);
-#endif
 
 const char *BLF_pgettext(const char *msgctxt, const char *msgid);
 
 /* translation */
-int BLF_translate_iface(void);
-int BLF_translate_tooltips(void);
+bool BLF_translate_iface(void);
+bool BLF_translate_tooltips(void);
 const char *BLF_translate_do_iface(const char *msgctxt, const char *msgid);
 const char *BLF_translate_do_tooltip(const char *msgctxt, const char *msgid);
 
@@ -83,17 +84,17 @@
 
 /* Those macros should be used everywhere in UI code. */
 #ifdef WITH_INTERNATIONAL
-/*	#define _(msgid) BLF_gettext(msgid) */
-	#define IFACE_(msgid) BLF_translate_do_iface(NULL, msgid)
-	#define TIP_(msgid) BLF_translate_do_tooltip(NULL, msgid)
-	#define CTX_IFACE_(context, msgid) BLF_translate_do_iface(context, msgid)
-	#define CTX_TIP_(context, msgid) BLF_translate_do_tooltip(context, msgid)
+/*#  define _(msgid) BLF_gettext(msgid) */
+#  define IFACE_(msgid) BLF_translate_do_iface(NULL, msgid)
+#  define TIP_(msgid) BLF_translate_do_tooltip(NULL, msgid)
+#  define CTX_IFACE_(context, msgid) BLF_translate_do_iface(context, msgid)
+#  define CTX_TIP_(context, msgid) BLF_translate_do_tooltip(context, msgid)
 #else
-/*	#define _(msgid) msgid */
-	#define IFACE_(msgid) msgid
-	#define TIP_(msgid) msgid
-	#define CTX_IFACE_(context, msgid) msgid
-	#define CTX_TIP_(context, msgid)   msgid
+/*#  define _(msgid) msgid */
+#  define IFACE_(msgid) msgid
+#  define TIP_(msgid)   msgid
+#  define CTX_IFACE_(context, msgid) msgid
+#  define CTX_TIP_(context, msgid)   msgid
 #endif
 
 /* Helper macro, when we want to define a same msgid for multiple msgctxt...
@@ -160,7 +161,7 @@
 
 #define BLF_I18NCONTEXTS_ITEM(ctxt_id, py_id) {#ctxt_id, py_id, ctxt_id}
 
-#define BLF_I18NCONTEXTS_DESC {                                                                                         \
+#define BLF_I18NCONTEXTS_DESC {                                                                                        \
 	BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_DEFAULT, "default"),                                                         \
 	BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "operator_default"),                                       \
 	BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_ACTION, "id_action"),                                                     \
@@ -198,6 +199,4 @@
 	{NULL, NULL, NULL}                                                                                                 \
 }
 
-//#undef _BLF_I18NCONTEXTS_ITEM
-
 #endif /* __BLF_TRANSLATION_H__ */

Modified: trunk/blender/source/blender/blenfont/intern/blf_lang.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_lang.c	2013-01-21 06:32:09 UTC (rev 53944)
+++ trunk/blender/source/blender/blenfont/intern/blf_lang.c	2013-01-21 08:08:20 UTC (rev 53945)
@@ -29,39 +29,33 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "RNA_types.h"
 
 #include "BLF_translation.h" /* own include */
 
-#include "BLI_utildefines.h"
+#include "BLI_fileops.h"
+#include "BLI_linklist.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
 
-#ifdef WITH_INTERNATIONAL
-
-#include <string.h>
-
-#include "boost_locale_wrapper.h"
-
 #include "BKE_global.h"
 
 #include "DNA_userdef_types.h"
 
 #include "MEM_guardedalloc.h"
 
-#include "BLI_fileops.h"
-#include "BLI_linklist.h"
-#include "BLI_path_util.h"
-#include "BLI_string.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) {
@@ -177,14 +171,20 @@
 
 	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 @@
 	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,17 +241,24 @@
 	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)
 {
+#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
@@ -299,32 +315,3 @@
 		MEM_freeN(_t);
 	}
 }
-
-#else /* ! WITH_INTERNATIONAL */
-
-struct EnumPropertyItem *BLF_RNA_lang_enum_properties(void)
-{
-	return NULL;
-}
-
-void BLF_lang_init(void)
-{
-	return;
-}
-
-void BLF_lang_free(void)
-{
-	return;
-}
-
-void BLF_lang_set(const char *UNUSED(str))
-{
-	return;
-}
-
-const char *BLF_lang_get(void)
-{
-	return "";
-}
-
-#endif /* WITH_INTERNATIONAL */

Modified: trunk/blender/source/blender/blenfont/intern/blf_translation.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_translation.c	2013-01-21 06:32:09 UTC (rev 53944)
+++ trunk/blender/source/blender/blenfont/intern/blf_translation.c	2013-01-21 08:08:20 UTC (rev 53945)
@@ -33,28 +33,28 @@
 
 #include "BLF_translation.h"
 
-#ifdef WITH_INTERNATIONAL
-
-#include "boost_locale_wrapper.h"
-
 #include "MEM_guardedalloc.h"
 
-#include "BLI_utildefines.h"
+#include "BLI_fileops.h"
 #include "BLI_path_util.h"
 #include "BLI_string.h"
-#include "BLI_path_util.h"
-#include "BLI_fileops.h"
 
 #include "DNA_userdef_types.h" /* For user settings. */
 
 #include "BPY_extern.h"
 
+#ifdef WITH_INTERNATIONAL
+
+#include "boost_locale_wrapper.h"
+
 static const char unifont_filename[] = "droidsans.ttf.gz";
 static unsigned char *unifont_ttf = NULL;
 static int unifont_size = 0;
+#endif  /* WITH_INTERNATIONAL */
 
 unsigned char *BLF_get_unifont(int *unifont_size_r)
 {
+#ifdef WITH_INTERNATIONAL
 	if (unifont_ttf == NULL) {
 		char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts");
 		if (fontpath) {
@@ -72,16 +72,21 @@
 	*unifont_size_r = unifont_size;
 
 	return unifont_ttf;
+#else
+	(void)unifont_size_r;
+	return NULL;
+#endif
 }
 
 void BLF_free_unifont(void)
 {
+#ifdef WITH_INTERNATIONAL
 	if (unifont_ttf)
 		MEM_freeN(unifont_ttf);
+#else
+#endif
 }
 
-#endif
-
 const char *BLF_pgettext(const char *msgctxt, const char *msgid)
 {
 #ifdef WITH_INTERNATIONAL
@@ -103,21 +108,21 @@
 #endif
 }
 
-int BLF_translate_iface(void)
+bool BLF_translate_iface(void)
 {
 #ifdef WITH_INTERNATIONAL
 	return (U.transopts & USER_DOTRANSLATE) && (U.transopts & USER_TR_IFACE);
 #else
-	return 0;
+	return false;
 #endif
 }
 
-int BLF_translate_tooltips(void)
+bool BLF_translate_tooltips(void)
 {
 #ifdef WITH_INTERNATIONAL
 	return (U.transopts & USER_DOTRANSLATE) && (U.transopts & USER_TR_TOOLTIPS);
 #else
-	return 0;
+	return false;
 #endif
 }
 




More information about the Bf-blender-cvs mailing list