~oh-dev/openhealth/phit-tools

« back to all changes in this revision

Viewing changes to ihris-suite/lib/i2ce/modules/Pages/modules/LocaleSelector/tools/make_configs.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
#!/usr/bin/php
 
2
<?php
 
3
/**
 
4
 * @copyright © 2009 Intrahealth International, Inc.
 
5
 * This File is part of I2CE
 
6
 *
 
7
 * I2CE is free software; you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 * 
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 * 
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 * @package I2CE
 
20
 * @subpackage Core
 
21
 * @author Carl Leitner <litlfred@ibiblio.org>
 
22
 * @version 2.1
 
23
 * @access public
 
24
 */
 
25
 
 
26
if (dirname(__FILE__) != getcwd()) {
 
27
    die("Please run in the tools subdirectory\n");
 
28
}
 
29
echo "Please increase your version in LocaleSelector.xml\n";
 
30
 
 
31
$lines = file('all_languages');
 
32
if ($lines === false) {
 
33
    die("Badness");
 
34
}
 
35
$lang = null;
 
36
$lang_trans = array();
 
37
$avail = array();
 
38
foreach ($lines as $i=>$line) {
 
39
    if (preg_match('/^\[(\w+?)\]\s*$/',$line,$matches)) {
 
40
        $lang = trim($matches[1]);
 
41
        $lang_trans[$lang] = array();
 
42
        continue;
 
43
    }
 
44
    if (preg_match('/^Name\[(\w+?)\]=(.*?)\s*$/',$line,$matches)) {
 
45
        if ($lang === null) {
 
46
            echo "Warning no language found but name found on line $i\n";
 
47
            continue;
 
48
        }
 
49
        $l = $matches[1];
 
50
        $trans = $matches[2];
 
51
    } else if (preg_match('/^Name=(.*?)\s*$/',$line,$matches)) { 
 
52
        if ($lang === null) {
 
53
            echo "Warning no language found but name found on line $i\n";
 
54
            continue;
 
55
        }
 
56
        $l = 'en_US';
 
57
        $trans = $matches[1];
 
58
    } else {
 
59
        continue;
 
60
    }
 
61
    $l = trim($l);
 
62
    $trans = trim($trans);
 
63
    if (strlen($l) == 0 || strlen($trans) == 0) {
 
64
        continue;
 
65
    }
 
66
    $lang_trans[$lang][$l] = $trans;
 
67
    $avail[$l] = true;
 
68
}
 
69
 
 
70
 
 
71
if (count($lang_trans) == 0) {
 
72
    die("No languages found\n");
 
73
}
 
74
if (!preg_match('/<version>(.+)<\/version>/',file_get_contents('../LocaleSelector.xml') , $matches)) {
 
75
    die ("No version found for locale selector module\n");
 
76
}
 
77
$version = $matches[1];
 
78
 
 
79
 
 
80
//http://www.i18nguy.com/temp/rtl.html
 
81
//http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
 
82
$RTLS = array(
 
83
    'ar','ara','arc','aze','az','cmc','div','dv','fa','fas','he',
 
84
              'jav','jv','jpr','jrb','kas','kaz','kk','ku','kur','ks','lad',
 
85
              'ma','mal','may','ms','msa','pa','pal','pan','peo','per','ps',
 
86
              'pus','sam','sd','so','som','snd','syc','syr','tmh','tk','tuk'
 
87
              ,'ug','uig','ur','urd');
 
88
 
 
89
 
 
90
$RTL_exprs =array( '/\p{Hebrew}/u', '/\p{Arabic}/u');
 
91
 
 
92
 
 
93
mb_internal_encoding("UTF-8");
 
94
foreach ($avail as $l=>$true) {
 
95
    $dir = '..' . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . $l;
 
96
    if (!is_dir($dir)) {
 
97
        if (!mkdir($dir,0775,true)) {
 
98
            die( "WARNING: Could not make $dir\n");
 
99
        }
 
100
    }            
 
101
    if ( ($dash_pos = strpos($l,'_')) === false ) {
 
102
        $two_letter = $l;
 
103
    } else {
 
104
        $two_letter = substr($l,0,$dash_pos);
 
105
    }
 
106
    $rtl = in_array( $two_letter, $RTLS);
 
107
 
 
108
    $out = '';
 
109
    if ($l != 'en_US') {
 
110
        $out .= '<?xml version="1.0"?>
 
111
<!DOCTYPE I2CEConfiguration SYSTEM "I2CE_Configuration.dtd">
 
112
<I2CEConfiguration name=\'localeSelector\'>     
 
113
  <metadata>
 
114
    <displayName>Locale Selector</displayName>   
 
115
    <className>I2CE_Module_LocaleSelector</className>
 
116
    <version>' . $version .'</version>
 
117
  </metadata>
 
118
  <configurationGroup name=\'localeSelector\' locale="'. $l  .'">
 
119
';
 
120
    }
 
121
    $out .= "    <configuration name='languages' path='/locales/languages'  values='many' type='delimited'>\n";
 
122
    $out .= "      <version>$version</version>\n";
 
123
    $added = false;
 
124
    foreach ($lang_trans as $lang=>$trans_data){
 
125
        if (count($trans_data) == 0) {
 
126
            continue;
 
127
        }
 
128
        if (!array_key_exists($l,$trans_data)) {
 
129
            continue;
 
130
        }
 
131
        $added = true;
 
132
        $trans = $trans_data[$l];
 
133
        if ($rtl) {
 
134
            if (($pos = mb_strpos($trans,'(')) !== false &&   ($pos2 = mb_strpos($trans,')')) !== false) {
 
135
                $all_parts = array( mb_substr($trans,0,$pos), mb_substr($trans,$pos+1, $pos2 - $pos -1));
 
136
            } else {
 
137
                $all_parts = array($trans);
 
138
            }            
 
139
            foreach ($all_parts as &$all_part) {
 
140
                $parts = preg_split('/ /u',$all_part);                
 
141
                foreach ($parts as $i=>&$part) {
 
142
                    $t_rtl = false;
 
143
                    foreach ($RTL_exprs as $RTL_expr) {
 
144
                        if (preg_match($RTL_expr,$part)) {
 
145
                            $t_rtl = true;
 
146
                            break;
 
147
                        }
 
148
                    }
 
149
                    if (!$t_rtl) {
 
150
                        continue;
 
151
                    }
 
152
                    $len = mb_strlen($part,'UTF-8');
 
153
                    $ps = array();
 
154
                    while ($len) {
 
155
                        $t = mb_substr($part,0,1,'UTF-8');
 
156
                        $ps[] = $t;
 
157
                        $part = mb_substr($part,1,$len,'UTF-8');
 
158
                        $len = mb_strlen($part);
 
159
                    }
 
160
                    $part = implode('', array_reverse($ps));
 
161
                }
 
162
                $all_part = implode(' ',array_reverse($parts));
 
163
            }
 
164
            if (count($all_parts) == 2) {
 
165
                $trans =  '(' . $all_parts[1] . ')' . $all_parts[0] ;
 
166
            } else {
 
167
                $trans = $all_parts[0];
 
168
            }
 
169
        }
 
170
        $out .= "      <value>$lang:" . $trans . "</value>\n";        
 
171
    }
 
172
    if (!$added) {
 
173
        continue;
 
174
    }
 
175
    $out .= "    </configuration>\n";
 
176
    if ($l != 'en_US') {
 
177
        $out .= "  </configurationGroup>\n</I2CEConfiguration>\n";
 
178
    }
 
179
    if ($l == 'en_US') {
 
180
        $file = $dir . DIRECTORY_SEPARATOR . 'Languages.xml';
 
181
    } else {
 
182
        $file = $dir . DIRECTORY_SEPARATOR . 'LocaleSelector.xml';
 
183
    }
 
184
    if (!file_put_contents($file,$out)) {
 
185
        die();
 
186
    }
 
187
    echo "Made $file\n";
 
188
}
 
189
# Local Variables:
 
190
# mode: php
 
191
# c-default-style: "bsd"
 
192
# indent-tabs-mode: nil
 
193
# c-basic-offset: 4
 
194
# End: