anewt-developers team mailing list archive
-
anewt-developers team
-
Mailing list archive
-
Message #00229
[Branch ~uws/anewt/anewt.uws] Rev 1765: [i18n] Implement dpgettext(), dnpgettext() and npgettext()
------------------------------------------------------------
revno: 1765
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt.uws
timestamp: Mon 2010-02-22 23:59:21 +0100
message:
[i18n] Implement dpgettext(), dnpgettext() and npgettext()
Extended the pgettext() logic to support text domains and
renamed it to dpgettext(); then pgettext() is just
convenience API that invokes dpgettext() with the default
text domain.
Also added the dnpgettext() function for plurals with
context, similar to the dpgettext() implementation. The
npgettext() function is, just like pgettext(), just
convenience API that invokes dnpgettext() with the default
text domain.
Also changed the i18n.make helper script so that it
correctly extracts all strings from source files.
Fixes bug #522405.
modified:
i18n/gettext.lib.php
scripts/i18n.make
--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws
Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription.
=== modified file 'i18n/gettext.lib.php'
--- i18n/gettext.lib.php 2010-02-22 22:56:16 +0000
+++ i18n/gettext.lib.php 2010-02-22 22:59:21 +0000
@@ -106,28 +106,54 @@
*
* This function can be used to provide context to the translator.
*
+ * \param $domain
+ * The text domain used for the lookup
* \param $ctx
* The context of the message.
- * \param $str
+ * \param $msgid
* The string to translate.
*
* \return
* The translated string, or the original string if no translation was
* found.
+ *
+ * \see pgettext
*/
-function pgettext($ctx, $str)
+function dpgettext($domain, $ctx, $msgid)
{
/* The .mo files generated by gettext > 0.15 have context separated from the
* message itself using 0x04 as a separator. */
- $str_with_prefix = sprintf("%s\004%s", $ctx, $str);
- $translated = gettext($str_with_prefix);
+ $msgid_with_ctx = sprintf("%s\004%s", $ctx, $msgid);
+ $translated = dgettext($domain, $msgid_with_ctx);
/* Translation succeeded? */
- if ($str_with_prefix != $translated)
+ if ($msgid_with_ctx != $translated)
return $translated;
- return $str;
+ return $msgid;
+}
+
+/**
+ * Translate a message with disambiguating context using the default text
+ * domain.
+ *
+ * This function can be used to provide context to the translator.
+ *
+ * \param $ctx
+ * The context of the message.
+ * \param $str
+ * The string to translate.
+ *
+ * \return
+ * The translated string, or the original string if no translation was
+ * found.
+ *
+ * \see dpgettext
+ */
+function pgettext($ctx, $str)
+{
+ return dpgettext(textdomain(null), $ctx, $str);
}
/**
@@ -141,6 +167,70 @@
return pgettext($ctx, $str);
}
+/**
+ * Translate a plural message with disambiguating context using the default text
+ * domain.
+ *
+ * This function can be used to provide context to the translator.
+ *
+ * \param $domain
+ * The text domain used for the lookup
+ * \param $ctx
+ * The context of the message.
+ * \param $msgid1
+ * The singular string to translate.
+ * \param $msgid1
+ * The plural string to translate.
+ * \param $n
+ * The count
+ *
+ * \return
+ * The translated string, or the original string if no translation was
+ * found.
+ *
+ * \see ngettext
+ * \see dpgettext
+ * \see npgettext
+ */
+function dnpgettext($domain, $ctx, $msgid1, $msgid2, $n)
+{
+ /* See dpgettext() implementation above */
+ $msgid1_with_ctx = sprintf("%s\004%s", $ctx, $msgid1);
+ $msgid2_with_ctx = sprintf("%s\004%s", $ctx, $msgid2);
+ $translated = dngettext($domain, $msgid1_with_ctx, $msgid2_with_ctx, $n);
+ $prefix = sprintf("%s\004", $ctx);
+ $translated = str_strip_prefix($translated, $prefix);
+ return $translated;
+}
+
+/**
+ * Translate a plural message with disambiguating context using the default text
+ * domain.
+ *
+ * This function can be used to provide context to the translator.
+ *
+ * \param $ctx
+ * The context of the message.
+ * \param $msgid1
+ * The singular string to translate.
+ * \param $msgid1
+ * The plural string to translate.
+ * \param $n
+ * The count
+ *
+ * \return
+ * The translated string, or the original string if no translation was
+ * found.
+ *
+ * \see ngettext
+ * \see dpgettext
+ * \see npgettext
+ */
+function npgettext($ctx, $msgid1, $msgid2, $n)
+{
+ return dnpgettext(textdomain(null), $ctx, $msgid1, $msgid2, $n);
+}
+
/* Check for the gettext() function. If it was not found, we include the
* fallback functions. */
=== modified file 'scripts/i18n.make'
--- scripts/i18n.make 2010-02-22 22:56:16 +0000
+++ scripts/i18n.make 2010-02-22 22:59:21 +0000
@@ -17,7 +17,7 @@
POFILES = $(wildcard *.po)
GMOFILES = $(POFILES:%.po=%.gmo)
-XGETTEXT_ARGS="--keyword=gettext_noop --keyword=pgettext:1c,2 --keyword=N_ --keyword=C_:1c,2 --keyword=Q_"
+XGETTEXT_ARGS="--keyword=gettext_noop --keyword=N_ --keyword=Q_ --keyword=pgettext:1c,2 --keyword=C_:1c,2 --keyword=dpgettext:2c,3 --keyword=npgettext:1c,2,3 --keyword=dnpgettext:2c,3,4"
%.gmo: %.po
@echo -n "$<: "