[aur-dev] [PATCH 1/2] Handle plurals in translations
Use ngettext() to handle plurals properly. Also, split pagination captions into two strings. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- 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): ?> <?php else: ?> <div id="pkglist-results" class="box"> <div class="pkglist-stats"> - <p><?= __('%d packages found. Page %d of %d.', $total, $current, $pages) ?></p> + <p> + <?= _n('%d package found.', '%d packages found.', $total) ?> + <?= __('Page %d of %d.', $current, $pages) ?> + </p> <?php if (count($templ_pages) > 1): ?> <p class="pkglist-nav"> <?php foreach ($templ_pages as $pagenr => $pagestart): ?> @@ -89,7 +92,10 @@ if (!$result): ?> </table> <div class="pkglist-stats"> - <p><?= __('%d packages found. Page %d of %d.', $total, $current, $pages) ?></p> + <p> + <?= _n('%d package found.', '%d packages found.', $total) ?> + <?= __('Page %d of %d.', $current, $pages) ?> + </p> <?php if (count($templ_pages) > 1): ?> <p class="pkglist-nav"> <?php foreach ($templ_pages as $pagenr => $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 @@ <div id="pkglist-results" class="box"> <div class="pkglist-stats"> - <p><?= __('%d package requests found. Page %d of %d.', $total, $current, $pages) ?></p> + <p> + <?= _n('%d package request found.', '%d package requests found.', $total) ?> + <?= __('Page %d of %d.', $current, $pages) ?> + </p> <?php if (count($templ_pages) > 1): ?> <p class="pkglist-nav"> <?php foreach ($templ_pages as $pagenr => $pagestart): ?> @@ -83,7 +86,10 @@ </table> <div class="pkglist-stats"> - <p><?= __('%d package requests found. Page %d of %d.', $total, $current, $pages) ?></p> + <p> + <?= _n('%d package request found.', '%d package requests found.', $total) ?> + <?= __('Page %d of %d.', $current, $pages) ?> + </p> <?php if (count($templ_pages) > 1): ?> <p class="pkglist-nav"> <?php foreach ($templ_pages as $pagenr => $pagestart): ?> -- 2.0.1
For packages with pending package requests, display the number of requests above the "File Request" link. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/pkgbasefuncs.inc.php | 5 ++++- web/lib/pkgfuncs.inc.php | 5 ++++- web/template/pkg_details.php | 1 + web/template/pkgbase_details.php | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index fed46c8..b357dff 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -187,7 +187,10 @@ function pkgbase_get_details($base_id) { $q.= "PackageBases.OutOfDateTS, PackageBases.SubmittedTS, "; $q.= "PackageBases.ModifiedTS, PackageBases.SubmitterUID, "; $q.= "PackageBases.MaintainerUID, PackageBases.PackagerUID, "; - $q.= "PackageCategories.Category "; + $q.= "PackageCategories.Category, "; + $q.= "(SELECT COUNT(*) FROM PackageRequests "; + $q.= " WHERE PackageRequests.PackageBaseID = PackageBases.ID "; + $q.= " AND PackageRequests.Status = 0) AS RequestCount "; $q.= "FROM PackageBases, PackageCategories "; $q.= "WHERE PackageBases.CategoryID = PackageCategories.ID "; $q.= "AND PackageBases.ID = " . intval($base_id); diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 7e65d09..a2b8a0d 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -401,7 +401,10 @@ function pkg_get_details($id=0) { $q.= "PackageBases.NumVotes, PackageBases.OutOfDateTS, "; $q.= "PackageBases.SubmittedTS, PackageBases.ModifiedTS, "; $q.= "PackageBases.SubmitterUID, PackageBases.MaintainerUID, "; - $q.= "PackageBases.PackagerUID, PackageCategories.Category "; + $q.= "PackageBases.PackagerUID, PackageCategories.Category, "; + $q.= "(SELECT COUNT(*) FROM PackageRequests "; + $q.= " WHERE PackageRequests.PackageBaseID = Packages.PackageBaseID "; + $q.= " AND PackageRequests.Status = 0) AS RequestCount "; $q.= "FROM Packages, PackageBases, PackageCategories "; $q.= "WHERE PackageBases.ID = Packages.PackageBaseID "; $q.= "AND PackageBases.CategoryID = PackageCategories.ID "; diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 065057a..6f39514 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -106,6 +106,7 @@ $sources = pkg_sources($row["ID"]); </form> </li> <?php endif; ?> + <li><span class="flagged"><?php if ($row["RequestCount"] > 0) { echo _n('%d pending request', '%d pending requests', $row["RequestCount"]); } ?></span></li> <li><a href="<?= get_pkgbase_uri($row['BaseName']) . 'request/'; ?>"><?= __('File Request'); ?></a></li> <?php if ($atype == "Trusted User" || $atype == "Developer"): ?> <li><a href="<?= get_pkgbase_uri($row['BaseName']) . 'delete/'; ?>"><?= __('Delete Package'); ?></a></li> diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index 2b92152..64df72b 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -81,6 +81,7 @@ $pkgs = pkgbase_get_pkgnames($base_id); </form> </li> <?php endif; ?> + <li><span class="flagged"><?php if ($row["RequestCount"] > 0) { echo _n('%d pending request', '%d pending requests', $row["RequestCount"]); } ?></span></li> <li><a href="<?= get_pkgbase_uri($row['Name']) . 'request/'; ?>"><?= __('File Request'); ?></a></li> <?php if ($atype == "Trusted User" || $atype == "Developer"): ?> <li><a href="<?= get_pkgbase_uri($row['Name']) . 'delete/'; ?>"><?= __('Delete Package'); ?></a></li> -- 2.0.1
participants (1)
-
Lukas Fleischer