From 7f29756196ce8743c474bb035d234a72af5381aa Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 4 Jul 2014 12:10:00 +0200 Subject: Handle plurals in translations Use ngettext() to handle plurals properly. Also, split pagination captions into two strings. Signed-off-by: Lukas Fleischer --- po/Makefile | 6 +++--- web/lib/translator.inc.php | 7 +++++++ web/template/pkg_search_results.php | 10 ++++++++-- web/template/pkgreq_results.php | 10 ++++++++-- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/po/Makefile b/po/Makefile index abe02fb..97e1822 100644 --- a/po/Makefile +++ b/po/Makefile @@ -47,9 +47,9 @@ all: ${MOFILES} update-pot: pkgname=AUR; \ pkgver=`sed -n 's/.*"AUR_VERSION", "\(.*\)".*/\1/p' ../web/lib/version.inc.php`; \ - xgettext --default-domain=aur -L php --keyword=__ --no-location \ - --add-comments=TRANSLATORS: --package-name="$$pkgname" \ - --package-version="$$pkgver" \ + xgettext --default-domain=aur -L php --keyword=__ --keyword=_n:1,2 \ + --no-location --add-comments=TRANSLATORS: \ + --package-name="$$pkgname" --package-version="$$pkgver" \ --msgid-bugs-address='${MSGID_BUGS_ADDRESS}' \ --directory ../web --files-from POTFILES -o aur.pot diff --git a/web/lib/translator.inc.php b/web/lib/translator.inc.php index 5117b99..448c41b 100644 --- a/web/lib/translator.inc.php +++ b/web/lib/translator.inc.php @@ -70,6 +70,13 @@ function __() { return $translated; } +function _n($msgid1, $msgid2, $n) { + global $l10n; + + $translated = sprintf($l10n->ngettext($msgid1, $msgid2, $n), $n); + return htmlspecialchars($translated, ENT_QUOTES); +} + # set up the visitor's language # function set_lang() { diff --git a/web/template/pkg_search_results.php b/web/template/pkg_search_results.php index e47fcb2..75131fc 100644 --- a/web/template/pkg_search_results.php +++ b/web/template/pkg_search_results.php @@ -12,7 +12,10 @@ if (!$result): ?>
-

+

+ + +

1): ?>

$pagestart): ?> @@ -89,7 +92,10 @@ if (!$result): ?>

-

+

+ + +

1): ?>

$pagestart): ?> diff --git a/web/template/pkgreq_results.php b/web/template/pkgreq_results.php index 261a1f7..2898bd5 100644 --- a/web/template/pkgreq_results.php +++ b/web/template/pkgreq_results.php @@ -1,6 +1,9 @@

-

+

+ + +

1): ?>

$pagestart): ?> @@ -83,7 +86,10 @@

-

+

+ + +

1): ?>

$pagestart): ?> -- cgit v1.2.3-54-g00ecf