summaryrefslogtreecommitdiff
path: root/includes/gettext.h
diff options
context:
space:
mode:
authorSimon Quigley <tsimonq2@ubuntu.com>2017-08-16 04:32:39 -0500
committerSimon Quigley <tsimonq2@ubuntu.com>2017-08-16 04:32:39 -0500
commit9a9db98089717990cd5e0eef529f6bb0819ebe46 (patch)
treea9afaabce984d5fe552fa8bf1a9405db9bdd2699 /includes/gettext.h
parent69a2124e9a081518297951256eb5c8d72d93361f (diff)
New upstream version 0.5.1+git20170815
Diffstat (limited to 'includes/gettext.h')
-rw-r--r--includes/gettext.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/includes/gettext.h b/includes/gettext.h
new file mode 100644
index 00000000..fcdb2051
--- /dev/null
+++ b/includes/gettext.h
@@ -0,0 +1,47 @@
+
+#ifndef __GETTEXT_H__
+#define __GETTEXT_H__
+
+#include <string.h>
+#include <libintl.h>
+#include <locale.h>
+
+static const char *
+__pgettext_expr (const char *msgctxt, const char *msgid)
+{
+ size_t msgctxt_len = strlen (msgctxt) + 1;
+ size_t msgid_len = strlen (msgid) + 1;
+ const char *translation;
+#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+ char msg_ctxt_id[msgctxt_len + msgid_len];
+#else
+ char buf[1024];
+ char *msg_ctxt_id =
+ (msgctxt_len + msgid_len <= sizeof (buf)
+ ? buf
+ : (char *) malloc (msgctxt_len + msgid_len));
+ if (msg_ctxt_id != NULL)
+#endif
+ {
+ int found_translation;
+ memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
+ msg_ctxt_id[msgctxt_len - 1] = '\004';
+ memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
+ translation = gettext (msg_ctxt_id);
+ found_translation = (translation != msg_ctxt_id);
+#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+ if (msg_ctxt_id != buf)
+ free (msg_ctxt_id);
+#endif
+ if (found_translation)
+ return translation;
+ }
+ return msgid;
+}
+
+#define _(STRING) gettext(STRING)
+#define N_(STRING) (STRING)
+#define C_(CTX, STRING) __pgettext_expr(CTX, STRING)
+#define NC_(CTX, STRING) (STRING)
+
+#endif