Annotation of /mambo/branches/4.6/administrator/components/com_languages/actions/save.action.php
Parent Directory
|
Revision Log
Revision 1756 - (view) (download)
| 1 : | csouza | 298 | <?php |
| 2 : | elpie | 971 | /** |
| 3 : | * @package Mambo | ||
| 4 : | * @subpackage Languages | ||
| 5 : | elpie | 1715 | * @author Mambo Foundation Inc see README.php |
| 6 : | elpie | 1756 | * @copyright (C) 2000 - 2009 Mambo Foundation Inc. |
| 7 : | elpie | 1715 | * See COPYRIGHT.php for copyright notices and details. |
| 8 : | * @license GNU/GPL Version 2, see LICENSE.php | ||
| 9 : | elpie | 1756 | * |
| 10 : | * Redistributions of files must retain the above copyright notice. | ||
| 11 : | * | ||
| 12 : | elpie | 1715 | * Mambo is free software; you can redistribute it and/or |
| 13 : | * modify it under the terms of the GNU General Public License | ||
| 14 : | * as published by the Free Software Foundation; version 2 of the License. | ||
| 15 : | */ | ||
| 16 : | ocs_cms | 1396 | |
| 17 : | andphe | 915 | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); |
| 18 : | csouza | 298 | class saveAction extends Action |
| 19 : | { | ||
| 20 : | function execute(&$controller, &$request) | ||
| 21 : | { | ||
| 22 : | csouza | 403 | $iso639 = strtolower(mosGetParam($_POST, 'iso639')); |
| 23 : | $iso3166 = mosGetParam($_POST, 'iso3166_2'); | ||
| 24 : | andphe | 908 | $iso3166_3 = mosGetParam($_POST, 'iso3166_3'); |
| 25 : | csouza | 403 | $lang = $iso639; |
| 26 : | $lang .= strlen($iso3166) == 2 ? '_'.$iso3166 : ''; | ||
| 27 : | $root = mamboCore::get('rootPath'); | ||
| 28 : | $langfile = $root.'/language/'.$lang.'.xml'; | ||
| 29 : | andphe | 1680 | $act = mosGetParam($_POST,'act'); |
| 30 : | |||
| 31 : | switch ($act) | ||
| 32 : | csouza | 298 | { |
| 33 : | csouza | 403 | case 'language': |
| 34 : | if (file_exists($langfile)) { | ||
| 35 : | csouza | 556 | $this->updatelanguage($lang); |
| 36 : | csouza | 298 | } |
| 37 : | csouza | 403 | else { |
| 38 : | andphe | 908 | $this->createlanguage($iso639, $iso3166, $iso3166_3); |
| 39 : | csouza | 403 | } |
| 40 : | ninekrit | 909 | return $controller->redirect('index', 'language'); |
| 41 : | csouza | 403 | break; |
| 42 : | case 'catalogs': | ||
| 43 : | default: | ||
| 44 : | andphe | 879 | $this->updatecatalog(false); |
| 45 : | csouza | 407 | return $controller->redirect('index', 'catalogs'); |
| 46 : | csouza | 403 | break; |
| 47 : | } | ||
| 48 : | } | ||
| 49 : | |||
| 50 : | csouza | 407 | |
| 51 : | |||
| 52 : | andphe | 908 | function createLanguage($iso639, $iso3166, $iso3166_3) { |
| 53 : | csouza | 556 | $locales = mamboLanguage::getLocales(); |
| 54 : | csouza | 403 | $default = $locales['locales'][$iso639]; |
| 55 : | $lang = $iso639; | ||
| 56 : | $lang .= strlen($iso3166) == 2 ? '_'.$iso3166 : ''; | ||
| 57 : | andphe | 1680 | $pluralform = mosGetParam($_POST,'plural_form'); |
| 58 : | |||
| 59 : | csouza | 556 | $language =& new mamboLanguage($lang); |
| 60 : | csouza | 403 | foreach ($default as $k => $v) { |
| 61 : | if (in_array($k, array_keys(get_class_vars(get_class($language))))) { | ||
| 62 : | $language->$k = $v; | ||
| 63 : | csouza | 298 | } |
| 64 : | csouza | 403 | } |
| 65 : | foreach ($_POST as $k => $v) { | ||
| 66 : | if (in_array($k, array_keys(get_class_vars(get_class($language))))) { | ||
| 67 : | $language->$k = $v; | ||
| 68 : | } | ||
| 69 : | } | ||
| 70 : | $language->name = $lang; | ||
| 71 : | $language->description = $language->title.' Locale'; | ||
| 72 : | if (!empty($language->territory)) $language->description .= ' For '.$language->territory; | ||
| 73 : | $language->locale = $lang.'.'.$language->charset.','.$lang.','.$iso639.','.strtolower($language->title); | ||
| 74 : | andphe | 908 | $language->iso3166_3 = $iso3166_3; |
| 75 : | csouza | 403 | $language->creationdate = date('d-m-Y'); |
| 76 : | $language->author = 'Mambo Foundation Inc.'; | ||
| 77 : | $language->authorurl = 'http://www.mambo-foundation.org'; | ||
| 78 : | $language->authoremail = 'translation@mambo-foundation.org'; | ||
| 79 : | cauld | 948 | $language->copyright = 'Refer to copyright.php'; |
| 80 : | elpie | 1715 | $language->license = 'http://www.opensource.org/licenses/gpl-2.0.php GNU/GPL'; |
| 81 : | andphe | 1680 | $language->setPlurals($pluralform ); |
| 82 : | csouza | 403 | |
| 83 : | csouza | 561 | $textdomain = rtrim($language->path, '\/'); |
| 84 : | $dir = $textdomain.'/'.$language->name; | ||
| 85 : | $untranslated = $textdomain.'/untranslated'; | ||
| 86 : | $charset = $language->charset; | ||
| 87 : | $langfiles = mosReadDirectory($untranslated,'.pot$'); | ||
| 88 : | csouza | 403 | @mkdir($dir); |
| 89 : | @mkdir($dir.'/LC_MESSAGES'); | ||
| 90 : | csouza | 561 | |
| 91 : | andphe | 908 | //$gettext_admin = new PHPGettextAdmin(); |
| 92 : | csouza | 561 | foreach ($langfiles as $domain) { |
| 93 : | $domain = substr($domain,0,-4); | ||
| 94 : | andphe | 1010 | /*if (file_exists("$textdomain/glossary/$lang.$charset.po")) { |
| 95 : | csouza | 561 | copy("$textdomain/glossary/$lang.$charset.po", "$dir/$lang.po"); |
| 96 : | $gettext_admin->initialize_translation($domain, $textdomain, $lang, $charset); | ||
| 97 : | $gettext_admin->compile($lang, $textdomain, $charset); | ||
| 98 : | enjoyman | 826 | } else {*/ |
| 99 : | csouza | 561 | copy("$untranslated/$domain.pot", "$dir/$domain.po"); |
| 100 : | enjoyman | 826 | //} |
| 101 : | csouza | 561 | } |
| 102 : | enjoyman | 826 | //if (!file_exists("$textdomain/$lang/$lang.po")) { |
| 103 : | // @copy("$textdomain/glossary/untranslated.pot", "$textdomain/$lang/$lang.po"); | ||
| 104 : | //} | ||
| 105 : | csouza | 403 | $language->save(); |
| 106 : | } | ||
| 107 : | csouza | 561 | |
| 108 : | csouza | 556 | function updatelanguage($lang) |
| 109 : | { | ||
| 110 : | andphe | 1680 | $pluralform = mosGetParam($_POST,'plural_form'); |
| 111 : | |||
| 112 : | csouza | 556 | $language =& new mamboLanguage($lang); |
| 113 : | $language->load(); | ||
| 114 : | foreach ($_POST as $k => $v) { | ||
| 115 : | if (in_array($k, array_keys(get_class_vars(get_class($language))))) { | ||
| 116 : | $language->$k = $v; | ||
| 117 : | } | ||
| 118 : | } | ||
| 119 : | andphe | 1680 | $language->setPlurals($pluralform); |
| 120 : | csouza | 556 | $language->save(); |
| 121 : | } | ||
| 122 : | |||
| 123 : | function updatecatalog($compile = true, $add_to_dict = true) | ||
| 124 : | { | ||
| 125 : | |||
| 126 : | andphe | 1680 | $domain = mosGetParam($_POST,'domain'); |
| 127 : | $textdomain = mosGetParam($_POST,'textdomain'); | ||
| 128 : | $lang = mosGetParam($_POST,'lang'); | ||
| 129 : | $comments = mosGetParam($_POST,'comments'); | ||
| 130 : | $headers = mosGetParam($_POST,'headers'); | ||
| 131 : | csouza | 556 | |
| 132 : | $catalog = new PHPGettext_catalog($domain, $textdomain); | ||
| 133 : | $catalog->setproperty('mode', 'po'); | ||
| 134 : | $catalog->setproperty('lang', $lang); | ||
| 135 : | $catalog->load(); | ||
| 136 : | |||
| 137 : | andphe | 1680 | $catalog->setComments($comments); |
| 138 : | $catalog->setHeaders($headers); | ||
| 139 : | andphe | 1219 | $plural_forms = $catalog->headers['Plural-Forms']; |
| 140 : | preg_match('/nplurals[\s]*[=]{1}[\s]*([\d]+);[\s]*plural[\s]*[=]{1}[\s]*(.*);/', $plural_forms, $matches); | ||
| 141 : | $is_plural = $matches[1] > 1; | ||
| 142 : | csouza | 556 | foreach ($_POST as $key => $value) { |
| 143 : | ninekrit | 775 | if (preg_match('/^([a-z]+[_]?[a-z]+?)[_]?([0-9]+)?_([0-9]+)$/', $key, $matches)) { |
| 144 : | csouza | 556 | switch ($matches[1]) |
| 145 : | { | ||
| 146 : | case 'msgid': | ||
| 147 : | andphe | 1010 | if (get_magic_quotes_gpc() == 1){ |
| 148 : | $value = stripslashes($value); | ||
| 149 : | //$value = htmlentities($value); | ||
| 150 : | } | ||
| 151 : | csouza | 556 | $messages[$matches[3]]['msgid'] = $value; |
| 152 : | break; | ||
| 153 : | case 'msgid_plural': | ||
| 154 : | andphe | 1219 | if ($is_plural){ |
| 155 : | $messages[$matches[3]]['msgid_plural'] = $value; | ||
| 156 : | } | ||
| 157 : | csouza | 556 | break; |
| 158 : | case 'msgstr': | ||
| 159 : | if (!empty($messages[$matches[3]]['msgid_plural'])) { | ||
| 160 : | |||
| 161 : | if ($matches[2] != '') { | ||
| 162 : | $messages[$matches[3]]['msgstr'][$matches[2]] = stripslashes($value); | ||
| 163 : | } else { | ||
| 164 : | $messages[$matches[3]]['msgstr'][0] = stripslashes($value); | ||
| 165 : | $messages[$matches[3]]['msgstr'][1] = ''; | ||
| 166 : | } | ||
| 167 : | } else { | ||
| 168 : | $messages[$matches[3]]['msgstr'] = stripslashes($value); | ||
| 169 : | } | ||
| 170 : | break; | ||
| 171 : | case 'fuzzy': | ||
| 172 : | $messages[$matches[3]]['fuzzy'] = $value == 'true' ? true : false; | ||
| 173 : | break; | ||
| 174 : | } | ||
| 175 : | } | ||
| 176 : | } | ||
| 177 : | foreach ($messages as $index => $arr) { | ||
| 178 : | if (strcmp($catalog->strings[$index]->msgid, $arr['msgid']) == 0) { | ||
| 179 : | $catalog->strings[$index]->setmsgstr($arr['msgstr']); | ||
| 180 : | andphe | 1219 | $catalog->strings[$index]->msgid_plural = isset($arr['msgid_plural'])?$arr['msgid_plural']:null;; |
| 181 : | $catalog->strings[$index]->setfuzzy($arr['fuzzy']); | ||
| 182 : | csouza | 556 | } |
| 183 : | } | ||
| 184 : | $catalog->save(); | ||
| 185 : | |||
| 186 : | andphe | 914 | $language = new mamboLanguage($lang); |
| 187 : | $language->save(); | ||
| 188 : | csouza | 556 | |
| 189 : | andphe | 1637 | $configuration =& mamboCore::getMamboCore(); |
| 190 : | $gettext_admin = new PHPGettextAdmin($configuration->get('mosConfig_locale_use_gettext')); | ||
| 191 : | andphe | 1660 | $gettext_admin->add_to_dict($domain, $textdomain, $lang, $language->charset, $language->plural_form['expression']); |
| 192 : | csouza | 556 | $catalog->load(); |
| 193 : | |||
| 194 : | if ($compile) { | ||
| 195 : | $catalog->setproperty('mode', 'mo'); | ||
| 196 : | $catalog->save(); | ||
| 197 : | } | ||
| 198 : | andphe | 914 | |
| 199 : | csouza | 556 | } |
| 200 : | csouza | 298 | } |
| 201 : | |||
| 202 : | |||
| 203 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

