summaryrefslogtreecommitdiff
path: root/lib/language.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-11-19 09:04:56 -0500
committerEvan Prodromou <evan@status.net>2009-11-19 09:04:56 -0500
commitb657e49ec772aec2b60ae193252edd53d85e1df5 (patch)
tree71f6054ac22b8355f434fd9bf4c2ccfc1afc5140 /lib/language.php
parentfa35dab2265aba78f7c704c34eaef4100bddfd70 (diff)
parent269781280903d80141788225ec858fbf6501971d (diff)
Merge branch '0.9.x' into mapstraction
Diffstat (limited to 'lib/language.php')
-rw-r--r--lib/language.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/language.php b/lib/language.php
index 2570907b7..a99bf89e3 100644
--- a/lib/language.php
+++ b/lib/language.php
@@ -32,6 +32,63 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
+if (!function_exists('gettext')) {
+ require_once("php-gettext/gettext.inc");
+}
+
+if (!function_exists('pgettext')) {
+ /**
+ * Context-aware gettext wrapper; use when messages in different contexts
+ * won't be distinguished from the English source but need different translations.
+ * The context string will appear as msgctxt in the .po files.
+ *
+ * Not currently exposed in PHP's gettext module; implemented to be compat
+ * with gettext.h's macros.
+ *
+ * @param string $context context identifier, should be some key like "menu|file"
+ * @param string $msgid English source text
+ * @return string original or translated message
+ */
+ function pgettext($context, $msg)
+ {
+ $msgid = $context . "\004" . $msg;
+ $out = dcgettext(textdomain(NULL), $msgid, LC_MESSAGES);
+ if ($out == $msgid) {
+ return $msg;
+ } else {
+ return $out;
+ }
+ }
+}
+
+if (!function_exists('npgettext')) {
+ /**
+ * Context-aware ngettext wrapper; use when messages in different contexts
+ * won't be distinguished from the English source but need different translations.
+ * The context string will appear as msgctxt in the .po files.
+ *
+ * Not currently exposed in PHP's gettext module; implemented to be compat
+ * with gettext.h's macros.
+ *
+ * @param string $context context identifier, should be some key like "menu|file"
+ * @param string $msg singular English source text
+ * @param string $plural plural English source text
+ * @param int $n number of items to control plural selection
+ * @return string original or translated message
+ */
+ function npgettext($context, $msg, $plural, $n)
+ {
+ $msgid = $context . "\004" . $msg;
+ $out = dcngettext(textdomain(NULL), $msgid, $plural, $n, LC_MESSAGES);
+ if ($out == $msgid) {
+ return $msg;
+ } else {
+ return $out;
+ }
+ }
+}
+
+
/**
* Content negotiation for language codes
*