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')
-rw-r--r--source/blender/blenfont/BLF_translation.h5
-rw-r--r--source/blender/blenfont/intern/blf_lang.c9
-rw-r--r--source/blender/blenfont/intern/blf_translation.c45
3 files changed, 52 insertions, 7 deletions
diff --git a/source/blender/blenfont/BLF_translation.h b/source/blender/blenfont/BLF_translation.h
index ddbc9a6a760..ce53b76da01 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
+#define TEXT_DOMAIN_NAME "blender"
+
/* blf_translation.c */
#ifdef WITH_INTERNATIONAL
@@ -40,7 +42,8 @@ unsigned char *BLF_get_unifont(int *unifont_size);
void BLF_free_unifont(void);
#endif
-const char* BLF_gettext(const char *msgid);
+const char *BLF_gettext(const char *msgid);
+const char *BLF_pgettext(const char *context, const char *message);
/* blf_lang.c */
diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c
index 77f9542883c..430780b19a0 100644
--- a/source/blender/blenfont/intern/blf_lang.c
+++ b/source/blender/blenfont/intern/blf_lang.c
@@ -58,7 +58,6 @@
#include "BLI_utildefines.h"
#include "BLI_path_util.h"
-#define DOMAIN_NAME "blender"
#define SYSTEM_ENCODING_DEFAULT "UTF-8"
#define FONT_SIZE_DEFAULT 12
@@ -205,15 +204,15 @@ void BLF_lang_set(const char *str)
setlocale(LC_NUMERIC, "C");
- textdomain(DOMAIN_NAME);
- bindtextdomain(DOMAIN_NAME, global_messagepath);
- bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name);
+ textdomain(TEXT_DOMAIN_NAME);
+ bindtextdomain(TEXT_DOMAIN_NAME, global_messagepath);
+ bind_textdomain_codeset(TEXT_DOMAIN_NAME, global_encoding_name);
}
void BLF_lang_encoding(const char *str)
{
BLI_strncpy(global_encoding_name, str, sizeof(global_encoding_name));
- /* bind_textdomain_codeset(DOMAIN_NAME, encoding_name); */
+ /* bind_textdomain_codeset(TEXT_DOMAIN_NAME, encoding_name); */
}
#else /* ! WITH_INTERNATIONAL */
diff --git a/source/blender/blenfont/intern/blf_translation.c b/source/blender/blenfont/intern/blf_translation.c
index fe14f5d4d1c..1d82abcf32d 100644
--- a/source/blender/blenfont/intern/blf_translation.c
+++ b/source/blender/blenfont/intern/blf_translation.c
@@ -29,9 +29,19 @@
*/
#include <stdlib.h>
+#include <string.h>
#ifdef WITH_INTERNATIONAL
#include <libintl.h>
+#include <locale.h>
+
+#define GETTEXT_CONTEXT_GLUE "\004"
+
+/* needed for windows version of gettext */
+#ifndef LC_MESSAGES
+# define LC_MESSAGES 1729
+#endif
+
#endif
#include "MEM_guardedalloc.h"
@@ -91,6 +101,40 @@ const char* BLF_gettext(const char *msgid)
#endif
}
+const char *BLF_pgettext(const char *context, const char *message)
+{
+#ifdef WITH_INTERNATIONAL
+ char static_msg_ctxt_id[1024];
+ char *dynamic_msg_ctxt_id = NULL;
+ char *msg_ctxt_id;
+ const char *translation;
+
+ size_t overall_length = strlen(context) + strlen(message) + sizeof(GETTEXT_CONTEXT_GLUE) + 1;
+
+ if (overall_length > sizeof(static_msg_ctxt_id)) {
+ dynamic_msg_ctxt_id = malloc(overall_length);
+ msg_ctxt_id = dynamic_msg_ctxt_id;
+ }
+ else {
+ msg_ctxt_id = static_msg_ctxt_id;
+ }
+
+ sprintf(msg_ctxt_id, "%s%s%s", context, GETTEXT_CONTEXT_GLUE, message);
+
+ translation = (char*)dcgettext(TEXT_DOMAIN_NAME, msg_ctxt_id, LC_MESSAGES);
+
+ if (dynamic_msg_ctxt_id)
+ free(dynamic_msg_ctxt_id);
+
+ if (translation == msg_ctxt_id)
+ translation = message;
+
+ return translation;
+#else
+ return message;
+#endif
+}
+
int BLF_translate_iface(void)
{
#ifdef WITH_INTERNATIONAL
@@ -132,4 +176,3 @@ const char *BLF_translate_do_tooltip(const char *msgid)
return msgid;
#endif
}
-