From: tasn Date: Sun, 18 Sep 2011 07:53:41 +0000 (+0000) Subject: Elm gettext: Only translate if the app using elm is translatable. X-Git-Tag: REL_F_I9500_20120323_1~17^2~1779 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=89c763f9e612f14ce97b8a081e666e242a49c129;p=framework%2Fuifw%2Felementary.git Elm gettext: Only translate if the app using elm is translatable. It assumes gettext is initialized before the call to elm_init. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@63452 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/src/lib/elm_config.c b/src/lib/elm_config.c index 3be17fa..319a0d5 100644 --- a/src/lib/elm_config.c +++ b/src/lib/elm_config.c @@ -1658,12 +1658,33 @@ elm_mirrored_set(Eina_Bool mirrored) _elm_rescale(); } +static void +_translation_init() +{ +#ifdef ENABLE_NLS + const char *cur_dom = textdomain(NULL); + const char *trans_comment = gettext(""); + const char *msg_locale = setlocale(LC_MESSAGES, NULL); + + /* Same concept as what glib does: + * We shouldn't translate if there are no translations for the + * application in the current locale + domain. (Unless locale is + * en_/C where translating only parts of the interface make some + * sense). + */ + _elm_config->translate = !(strcmp (cur_dom, "messages") && + !*trans_comment && strncmp (msg_locale, "en_", 3) && + strcmp (msg_locale, "C")); +#endif +} + void _elm_config_init(void) { _desc_init(); _profile_fetch_from_conf(); _config_load(); + _translation_init(); _env_get(); _config_apply(); _elm_config_font_overlay_apply(); diff --git a/src/lib/elm_priv.h b/src/lib/elm_priv.h index a866a2e..e6ff20b 100644 --- a/src/lib/elm_priv.h +++ b/src/lib/elm_priv.h @@ -28,7 +28,7 @@ #ifdef ENABLE_NLS # include -# define E_(string) dgettext(PACKAGE, string) +# define E_(string) _elm_dgettext(string) #else # define bindtextdomain(domain,dir) # define E_(string) (string) @@ -148,6 +148,7 @@ struct _Elm_Config /* Not part of the EET file */ Eina_Bool is_mirrored : 1; + Eina_Bool translate : 1; }; struct _Elm_Module @@ -247,6 +248,20 @@ extern int _elm_log_dom; extern Eina_List *_elm_win_list; extern int _elm_win_deferred_free; +/* Our gettext wrapper, used to disable translation of elm if the app + * is not translated. */ +static inline const char * +_elm_dgettext(const char *string) +{ + if (EINA_UNLIKELY(_elm_config->translate == EINA_FALSE)) + { + return string; + } + + return dgettext(PACKAGE, string); +} + + /* Used by the paste handler */ void _elm_entry_entry_paste(Evas_Object *obj, const char *entry);