~oh-dev/openhealth/phit-tools

« back to all changes in this revision

Viewing changes to ihris-suite/lib/i2ce/modules/TemplateData/modules/Tags/tools/pluralforms.php

  • Committer: litlfred at ibiblio
  • Date: 2009-10-26 13:55:16 UTC
  • Revision ID: litlfred@ibiblio.org-20091026135516-7er0260tad01febt
ihris suite updated to 4.0.1 pre-release...
follows that did not get added on the last attempt did this time... the problem is that bzr does not like to include branches in a sub-directory even if you add them in which 
  is how ihris-suite/lib/* was structed.  so i had to move ihris-suite/lib/*/.bzr to ihris-suite/lib/*/.bzr_dir to trick it
the site will now succesfully install.  have not attempted change the root drive letter yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
 
 
4
// reads in table from http://translate.sourceforge.net/wiki/l10n/pluralforms#plural_forms 
 
5
 
 
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");
 
12
}
 
13
 
 
14
$forms = array();
 
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");
 
20
        continue;
 
21
    }
 
22
    if ($cells->length !== 3) {
 
23
        fwrite(STDERR, "Unpxected number of cells " . $cells->length ." on row $i\n\t" . $row->textContent . "\n");
 
24
        continue;
 
25
    }
 
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");
 
30
        continue;
 
31
    } else {
 
32
        $nplurals = $matches[1];
 
33
    }
 
34
    $forms[$lang] = array('nplurals'=>$nplurals, 'equation'=>$eq);
 
35
}
 
36
//print_r($forms);
 
37
echo '<?php
 
38
/**
 
39
 * @copyright © 2007, 2008, 2009 Intrahealth International, Inc.
 
40
 * This File is part of I2CE
 
41
 *
 
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.
 
46
 * 
 
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.
 
51
 * 
 
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/>.
 
54
 */
 
55
/**
 
56
 * The plural forms for various languages according to http://translate.sourceforge.net/wiki/l10n/pluralforms#plural_forms
 
57
 * 
 
58
 * @package iHRIS
 
59
 * @subpackage Common
 
60
 * @access public
 
61
 * @author Frederick Leitner <litlfred@ibiblio.org>
 
62
 * @since v2.0.0
 
63
 * @version v2.0.0
 
64
 */
 
65
 
 
66
/**
 
67
 * The page class for displaying the home page.
 
68
 * @package iHRIS
 
69
 * @subpackage Common
 
70
 * @access public
 
71
 */
 
72
class I2CE_PluralForms extends I2CE_Fuzzy {
 
73
 
 
74
 
 
75
 
 
76
    /**
 
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
 
79
     */
 
80
    public function getPluralForm($lang,$n) {
 
81
        if (!is_string($lang)) {
 
82
            return false;
 
83
        }
 
84
        if (!is_numeric($n)) {
 
85
            return false;
 
86
        }
 
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)) {
 
95
                            return false;
 
96
                        }
 
97
                    }
 
98
                }
 
99
            }
 
100
        } 
 
101
        return $this->$method($n);
 
102
    }
 
103
 
 
104
   
 
105
 
 
106
';
 
107
 
 
108
foreach ($forms as $lang=>$data) {
 
109
    echo "
 
110
    public function getPluralForm_$lang(\$n) {\n";
 
111
    $eq = explode('=',trim($data['equation']),2);
 
112
    $eq = $eq[1];
 
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) {
 
120
            return false;
 
121
        } else { 
 
122
            return \$plural;
 
123
        }
 
124
    }
 
125
";
 
126
}
 
127
 
 
128
 
 
129
echo "\n}\n";
 
130
 
 
131
 
 
132
 
 
133
 
 
134
 
 
135
# Local Variables:
 
136
# mode: php
 
137
# c-default-style: "bsd"
 
138
# indent-tabs-mode: nil
 
139
# c-basic-offset: 4
 
140
# End: