adding dgettext and dngettext function support and additional $l10n array safety...
[squirrelmail.git] / functions / ngettext.php
CommitLineData
3b84e1b1 1<?php
2/**
3 * SquirrelMail internal ngettext functions
4 *
5 * Uses php-gettext classes
6 *
6c84ba1e 7 * Copyright (c) 2004-2005 The SquirrelMail Project Team
3b84e1b1 8 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 *
6c84ba1e 10 * @copyright (c) 2004-2005 The SquirrelMail Project Team
3b84e1b1 11 * @license http://opensource.org/licenses/gpl-license.php GNU Public Licens
12 * @link http://www.php.net/gettext Original php gettext manual
13 * @link http://savannah.nongnu.org/projects/php-gettext php-gettext classes
14 * @version $Id$
15 * @package squirrelmail
16 * @subpackage i18n
84524796 17 * @since 1.5.1
3b84e1b1 18 */
19
20/**
21 * internal ngettext wrapper.
22 *
23 * provides ngettext support
84524796 24 * @since 1.5.1
3b84e1b1 25 * @link http://www.php.net/function.ngettext
26 * @param string $single English string, singular form
27 * @param string $plural English string, plural form
28 * @param integer $number number that shows used quantity
29 * @return string translated string
30 */
31function ngettext($single, $plural, $number) {
32 global $l10n, $gettext_domain;
a9a10f57 33 if (! isset($l10n[$gettext_domain]) ||
34 ! is_object($l10n[$gettext_domain]) ||
35 $l10n[$gettext_domain]->error==1)
36 return ($number==1 ? $single : $plural);
3b84e1b1 37 return $l10n[$gettext_domain]->ngettext($single, $plural, $number);
38}
a9a10f57 39
40/**
41 * safety check.
42 * freaky setup where ngettext is not available and dngettext is available.
43 */
44if (! function_exists('dngettext')) {
45 /**
46 * internal dngettext wrapper.
47 *
48 * provides dngettext support
49 * @since 1.5.1
50 * @link http://www.php.net/function.dngettext
51 * @param string $domain Gettext domain
52 * @param string $single English string, singular form
53 * @param string $plural English string, plural form
54 * @param integer $number number that shows used quantity
55 * @return string translated string
56 */
57 function dngettext($domain, $single, $plural, $number) {
58 global $l10n;
59 // Make sure that $number is integer
60 $number = (int) $number;
61
62 // Make sure that domain is initialized
63 if (! isset($l10n[$domain]) ||
64 ! is_object($l10n[$domain]) ||
65 $l10n[$domain]->error==1)
66 return ($number==1 ? $single : $plural);
67
68 // use ngettext class function
69 return $l10n[$domain]->ngettext($single, $plural, $number);
70 }
71}
e50f5ac2 72?>