diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2013-01-21 12:08:20 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2013-01-21 12:08:20 +0400 |
commit | 2b9ab8781d95609f529c2d5dcf770c82d23afe17 (patch) | |
tree | 2590a91787568ad539accff9a544c2240cd372fb /source | |
parent | 40629671f468a59a8fd8d5fa5953a848d19a5d44 (diff) |
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...
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenfont/BLF_translation.h | 35 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_lang.c | 73 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_translation.c | 31 |
3 files changed, 65 insertions, 74 deletions
diff --git a/source/blender/blenfont/BLF_translation.h b/source/blender/blenfont/BLF_translation.h index 7194c6c23c1..b90b5c60a36 100644 --- a/source/blender/blenfont/BLF_translation.h +++ b/source/blender/blenfont/BLF_translation.h @@ -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 @@ const char *BLF_lang_get(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. + * 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 @@ struct EnumPropertyItem *BLF_RNA_lang_enum_properties(void); /* 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 @@ const char *BLF_translate_do_tooltip(const char *msgctxt, const char *msgid); /* 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 @@ typedef struct #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 @@ typedef struct {NULL, NULL, NULL} \ } -//#undef _BLF_I18NCONTEXTS_ITEM - #endif /* __BLF_TRANSLATION_H__ */ diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index 4ce21200456..c7a54c8714c 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -29,18 +29,16 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "RNA_types.h" #include "BLF_translation.h" /* own include */ -#include "BLI_utildefines.h" - -#ifdef WITH_INTERNATIONAL - -#include <string.h> - -#include "boost_locale_wrapper.h" +#include "BLI_fileops.h" +#include "BLI_linklist.h" +#include "BLI_path_util.h" +#include "BLI_string.h" #include "BKE_global.h" @@ -48,10 +46,9 @@ #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; @@ -59,9 +56,6 @@ 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 @@ 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,17 +241,24 @@ 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) { +#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 @@ void BLF_locale_explode(const char *locale, char **language, char **country, cha 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 */ diff --git a/source/blender/blenfont/intern/blf_translation.c b/source/blender/blenfont/intern/blf_translation.c index 3aaa61d55f2..6394d1169cf 100644 --- a/source/blender/blenfont/intern/blf_translation.c +++ b/source/blender/blenfont/intern/blf_translation.c @@ -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,15 +72,20 @@ unsigned char *BLF_get_unifont(int *unifont_size_r) *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 +} const char *BLF_pgettext(const char *msgctxt, const char *msgid) { @@ -103,21 +108,21 @@ const char *BLF_pgettext(const char *msgctxt, const char *msgid) #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 } |