4
* @copyright © 2009 Intrahealth International, Inc.
5
* This File is part of I2CE
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.
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.
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/>.
21
* @author Carl Leitner <litlfred@ibiblio.org>
26
if (dirname(__FILE__) != getcwd()) {
27
die("Please run in the tools subdirectory\n");
29
echo "Please increase your version in LocaleSelector.xml\n";
31
$lines = file('all_languages');
32
if ($lines === false) {
36
$lang_trans = 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();
44
if (preg_match('/^Name\[(\w+?)\]=(.*?)\s*$/',$line,$matches)) {
46
echo "Warning no language found but name found on line $i\n";
51
} else if (preg_match('/^Name=(.*?)\s*$/',$line,$matches)) {
53
echo "Warning no language found but name found on line $i\n";
62
$trans = trim($trans);
63
if (strlen($l) == 0 || strlen($trans) == 0) {
66
$lang_trans[$lang][$l] = $trans;
71
if (count($lang_trans) == 0) {
72
die("No languages found\n");
74
if (!preg_match('/<version>(.+)<\/version>/',file_get_contents('../LocaleSelector.xml') , $matches)) {
75
die ("No version found for locale selector module\n");
77
$version = $matches[1];
80
//http://www.i18nguy.com/temp/rtl.html
81
//http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
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');
90
$RTL_exprs =array( '/\p{Hebrew}/u', '/\p{Arabic}/u');
93
mb_internal_encoding("UTF-8");
94
foreach ($avail as $l=>$true) {
95
$dir = '..' . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . $l;
97
if (!mkdir($dir,0775,true)) {
98
die( "WARNING: Could not make $dir\n");
101
if ( ($dash_pos = strpos($l,'_')) === false ) {
104
$two_letter = substr($l,0,$dash_pos);
106
$rtl = in_array( $two_letter, $RTLS);
110
$out .= '<?xml version="1.0"?>
111
<!DOCTYPE I2CEConfiguration SYSTEM "I2CE_Configuration.dtd">
112
<I2CEConfiguration name=\'localeSelector\'>
114
<displayName>Locale Selector</displayName>
115
<className>I2CE_Module_LocaleSelector</className>
116
<version>' . $version .'</version>
118
<configurationGroup name=\'localeSelector\' locale="'. $l .'">
121
$out .= " <configuration name='languages' path='/locales/languages' values='many' type='delimited'>\n";
122
$out .= " <version>$version</version>\n";
124
foreach ($lang_trans as $lang=>$trans_data){
125
if (count($trans_data) == 0) {
128
if (!array_key_exists($l,$trans_data)) {
132
$trans = $trans_data[$l];
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));
137
$all_parts = array($trans);
139
foreach ($all_parts as &$all_part) {
140
$parts = preg_split('/ /u',$all_part);
141
foreach ($parts as $i=>&$part) {
143
foreach ($RTL_exprs as $RTL_expr) {
144
if (preg_match($RTL_expr,$part)) {
152
$len = mb_strlen($part,'UTF-8');
155
$t = mb_substr($part,0,1,'UTF-8');
157
$part = mb_substr($part,1,$len,'UTF-8');
158
$len = mb_strlen($part);
160
$part = implode('', array_reverse($ps));
162
$all_part = implode(' ',array_reverse($parts));
164
if (count($all_parts) == 2) {
165
$trans = '(' . $all_parts[1] . ')' . $all_parts[0] ;
167
$trans = $all_parts[0];
170
$out .= " <value>$lang:" . $trans . "</value>\n";
175
$out .= " </configuration>\n";
177
$out .= " </configurationGroup>\n</I2CEConfiguration>\n";
180
$file = $dir . DIRECTORY_SEPARATOR . 'Languages.xml';
182
$file = $dir . DIRECTORY_SEPARATOR . 'LocaleSelector.xml';
184
if (!file_put_contents($file,$out)) {
191
# c-default-style: "bsd"
192
# indent-tabs-mode: nil