4
// reads in table from http://translate.sourceforge.net/wiki/l10n/pluralforms#plural_forms
6
$dom = new DOMDocument();
7
$dom->loadHTMLFile('pluralforms.html');
8
$xpath = new DOMXPath($dom);
9
$results = $xpath->query('//table/tbody/tr');
10
if (count($results) != 1) {
11
die('no results' . "\n");
15
for ($i = 0; $i < $results->length; $i++) {
16
$row = $results->item($i);
17
$cells = $xpath->query('./td',$row);
18
if ($cells->length == 0) {
19
fwrite(STDERR, "No cell on row $i\n");
22
if ($cells->length !== 3) {
23
fwrite(STDERR, "Unpxected number of cells " . $cells->length ." on row $i\n\t" . $row->textContent . "\n");
26
$lang = trim($cells->item(0)->textContent);
27
list($nplurals,$eq) = explode(';',trim($cells->item(2)->textContent));
28
if (!preg_match('/^\s*nplurals\s*=\s*(\d+)\s*$/',$nplurals,$matches)) {
29
fwrite(STDERR, "Could not find nplurals for $lang:\n\t" . $cells->item(2)->textContent . "\n");
32
$nplurals = $matches[1];
34
$forms[$lang] = array('nplurals'=>$nplurals, 'equation'=>$eq);
39
* @copyright © 2007, 2008, 2009 Intrahealth International, Inc.
40
* This File is part of I2CE
42
* I2CE is free software; you can redistribute it and/or modify it
43
* under the terms of the GNU General Public License as published by
44
* the Free Software Foundation; either version 3 of the License, or
45
* (at your option) any later version.
47
* This program is distributed in the hope that it will be useful,
48
* but WITHOUT ANY WARRANTY; without even the implied warranty of
49
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50
* GNU General Public License for more details.
52
* You should have received a copy of the GNU General Public License
53
* along with this program. If not, see <http://www.gnu.org/licenses/>.
56
* The plural forms for various languages according to http://translate.sourceforge.net/wiki/l10n/pluralforms#plural_forms
61
* @author Frederick Leitner <litlfred@ibiblio.org>
67
* The page class for displaying the home page.
72
class I2CE_PluralForms extends I2CE_Fuzzy {
77
* Given a locale/launguage and a integer, evaluates the plural form
78
* @returns mixed. false on failure, int the plural form used on success
80
public function getPluralForm($lang,$n) {
81
if (!is_string($lang)) {
84
if (!is_numeric($n)) {
87
$method = "getPluralForm_" . $lang;
88
if (! $this->_hasMethod($method)) {
89
if ( ($pos = strpos("_",$lang)) !== false) {
90
$method = "getPluralForm_" . substr($lang,0,$pos);
91
if (! $this->_hasMethod($method)) {
92
if ( ($pos = strpos("-",$lang)) !== false) {
93
$method = "getPluralForm_" . substr($lang,0,$pos);
94
if (! $this->_hasMethod($method)) {
101
return $this->$method($n);
108
foreach ($forms as $lang=>$data) {
110
public function getPluralForm_$lang(\$n) {\n";
111
$eq = explode('=',trim($data['equation']),2);
113
$eq = preg_replace('/n/','$n',$eq);
114
//make sure there is no spacing in our operators
115
$eq = preg_replace('/<\s+=/','<=',$eq);
116
$eq = preg_replace('/>\s+=/','>=',$eq);
117
$eq = preg_replace('/!\s+=/','!=',$eq);
118
echo " \$plural = (int) ($eq);\n";
119
echo " if (\$plural > {$data['nplurals']} || \$plural < 0) {
137
# c-default-style: "bsd"
138
# indent-tabs-mode: nil