当前位置: 首页>>代码示例>>PHP>>正文


PHP Translation::addTranslation方法代码示例

本文整理汇总了PHP中Translation::addTranslation方法的典型用法代码示例。如果您正苦于以下问题:PHP Translation::addTranslation方法的具体用法?PHP Translation::addTranslation怎么用?PHP Translation::addTranslation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Translation的用法示例。


在下文中一共展示了Translation::addTranslation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 public function save()
 {
     try {
         $id = $_POST['id'];
         $label = preg_replace("[\n|\r|\n\r]", ' ', $_POST['label']);
         $res = Translation::addTranslation('LABEL', $id, 'en', $label);
         if ($res['codError'] < 0) {
             $result->success = false;
             $result->msg = $res['message'];
         } else {
             $result->success = true;
             $result->msg = 'Label ' . $id . ' saved Successfully!';
         }
     } catch (Exception $e) {
         $result->success = false;
         $result->msg = $e->getMessage();
     }
     print G::json_encode($result);
 }
开发者ID:emildev35,项目名称:processmaker,代码行数:19,代码来源:ajaxListener.php

示例2: export

 public function export()
 {
     G::LoadSystem('i18n_po');
     G::LoadClass("system");
     //get labels MichelangeloFE
     try {
         $oTranslation = new Translation();
         $MichelangeloFE = PATH_HOME . "../workflow/public_html/lib/js";
         if (file_exists($MichelangeloFE)) {
             $labels = self::readLabelsDirectory($MichelangeloFE, true);
             foreach ($labels as $label) {
                 $oTranslation->addTranslation('LABEL', 'ID_MAFE_' . G::encryptOld($label), 'en', $label);
             }
         }
     } catch (Exception $e) {
         error_log($e->getMessage());
     }
     //creating the .po file
     $sPOFile = PATH_CORE . 'content' . PATH_SEP . 'translations' . PATH_SEP . MAIN_POFILE . '.' . $_GET['LOCALE'] . '.po';
     $poFile = new i18n_PO($sPOFile);
     $poFile->buildInit();
     $language = new Language();
     $locale = $_GET['LOCALE'];
     $_TARGET_LANG = $_GET['LOCALE'];
     $_BASE_LANG = 'en';
     if (strpos($locale, Translation::$localeSeparator) !== false) {
         list($LAN_ID, $IC_UID) = explode(Translation::$localeSeparator, $_GET['LOCALE']);
         $iCountry = new IsoCountry();
         $iCountryRecord = $iCountry->findById($IC_UID);
         if (!isset($iCountryRecord['IC_UID'])) {
             throw new Exception("Country Target ID '{$_GET['LAN_ID']}' doesn't exist!");
         }
         $sCountry = $iCountryRecord['IC_NAME'];
     } else {
         $LAN_ID = $locale;
         $sCountry = $IC_UID = '';
     }
     $langRecord = $language->findById($LAN_ID);
     if (!isset($langRecord['LAN_NAME'])) {
         throw new Exception("Language Target ID \"{$LAN_ID}\" doesn't exist!");
     }
     $sLanguage = $langRecord['LAN_NAME'];
     //setting headers
     $poFile->addHeader('Project-Id-Version', 'ProcessMaker ' . System::getVersion());
     $poFile->addHeader('POT-Creation-Date', '');
     $poFile->addHeader('PO-Revision-Date', date('Y-m-d H:i:s'));
     $poFile->addHeader('Last-Translator', '');
     $poFile->addHeader('Language-Team', 'Colosa Developers Team <developers@colosa.com>');
     $poFile->addHeader('MIME-Version', '1.0');
     $poFile->addHeader('Content-Type', 'text/plain; charset=utf-8');
     $poFile->addHeader('Content-Transfer_Encoding', '8bit');
     $poFile->addHeader('X-Poedit-Language', ucwords($sLanguage));
     $poFile->addHeader('X-Poedit-Country', ucwords($sCountry));
     $poFile->addHeader('X-Poedit-SourceCharset', 'utf-8');
     $poFile->addHeader('Content-Transfer-Encoding', '8bit');
     $aLabels = array();
     $aMsgids = array('' => true);
     // selecting all translations records of base language 'en' on TRANSLATIONS table
     $oCriteria = new Criteria('workflow');
     $oCriteria->addSelectColumn(TranslationPeer::TRN_CATEGORY);
     $oCriteria->addSelectColumn(TranslationPeer::TRN_ID);
     $oCriteria->addSelectColumn(TranslationPeer::TRN_VALUE);
     $oCriteria->add(TranslationPeer::TRN_LANG, 'en');
     $oDataset = TranslationPeer::doSelectRS($oCriteria);
     $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
     $targetLangRecords = array();
     // retrieve the translation for the target language
     if ($LAN_ID != 'en') {
         // only if it is different language than base language 'en'
         $c = new Criteria('workflow');
         $c->addSelectColumn(TranslationPeer::TRN_CATEGORY);
         $c->addSelectColumn(TranslationPeer::TRN_ID);
         $c->addSelectColumn(TranslationPeer::TRN_VALUE);
         $c->add(TranslationPeer::TRN_LANG, $_GET['LOCALE']);
         $ds = TranslationPeer::doSelectRS($c);
         $ds->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         while ($ds->next()) {
             $row = $ds->getRow();
             $targetLangRecords[$row['TRN_CATEGORY'] . '/' . $row['TRN_ID']] = $row['TRN_VALUE'];
         }
     }
     // get the respective translation for each english label
     while ($oDataset->next()) {
         $aRow1 = $oDataset->getRow();
         $trnCategory = trim($aRow1['TRN_CATEGORY']);
         # Validation, validate that the TRN_CATEGORY contains valid characteres
         preg_match("/^[0-9a-zA-Z_-]+/", $trnCategory, $sTestResult);
         // IF the translations id "TRN_ID" has invalid characteres or has not accepted categories
         if ($sTestResult[0] !== $trnCategory || $trnCategory != 'LABEL' && $trnCategory != 'JAVASCRIPT') {
             $oTranslation = new Translation();
             $oTranslation->remove($aRow1['TRN_CATEGORY'], $aRow1['TRN_ID'], 'en');
             //remove not accepted translations
             continue;
             //jump to next iteration
         }
         // retrieve the translation for the target language
         if ($LAN_ID != 'en') {
             // only if it is different language than base language 'en'
             if (isset($targetLangRecords[$aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID']])) {
                 $msgstr = $targetLangRecords[$aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID']] != '' ? $targetLangRecords[$aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID']] : $aRow1['TRN_VALUE'];
//.........这里部分代码省略.........
开发者ID:emildev35,项目名称:processmaker,代码行数:101,代码来源:Language.php

示例3: preg_replace

/**
 * translationsSave.php
 *
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2008 Colosa Inc.23
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
 * Coral Gables, FL, 33134, USA, or email info@colosa.com.
 */
$form = $_POST['form'];
require_once "classes/model/Translation.php";
$form['trn_value'] = preg_replace("[\n|\r|\n\r]", ' ', $form['trn_value']);
//$t = new Translation;
$res = Translation::addTranslation($form['trn_category'], $form['trn_id'], 'en', $form['trn_value']);
if ($res['codError'] < 0) {
    G::SendMessageText($res['message'], 'error');
}
G::Header('location: translations');
开发者ID:emildev35,项目名称:processmaker,代码行数:31,代码来源:translationsSave.php

示例4: import

 public function import($sLanguageFile, $updateXml = true, $updateDB = true)
 {
     try {
         G::LoadSystem('i18n_po');
         $POFile = new i18n_PO($sLanguageFile);
         $POFile->readInit();
         $POHeaders = $POFile->getHeaders();
         /*getting the PO Language definition*/
         $langName = $POHeaders['X-Poedit-Language'];
         //find the lang id
         $language = new Language();
         $langRecord = $language->findByLanName($langName);
         if (!isset($langRecord['LAN_ID'])) {
             $langRecord = $language->findById($langName);
             if (!isset($langRecord['LAN_ID'])) {
                 //if the language doesn't exist abort
                 throw new Exception('The .po file has a invalid X-Poedit-Language definition!');
             }
         }
         $languageID = $langRecord['LAN_ID'];
         /*getting the PO Language definition*/
         $countryName = $POHeaders['X-Poedit-Country'];
         if ($countryName != '.') {
             $isoCountry = new IsoCountry();
             $countryRecord = $isoCountry->findByIcName($countryName);
             if (!isset($countryRecord['IC_UID'])) {
                 //if the language doesn't exist abort
                 throw new Exception('The .po file has a invalid X-Poedit-Country definition!');
             }
             $countryID = $countryRecord['IC_UID'];
             //define locale
             $LOCALE = "{$languageID}-{$countryID}";
         } else {
             $LOCALE = $languageID;
         }
         $oTranslation = new Translation();
         $countItems = 0;
         $countItemsSuccess = 0;
         $errorMsg = '';
         while ($rowTranslation = $POFile->getTranslation()) {
             $countItems++;
             if (!isset($POFile->translatorComments[0]) || !isset($POFile->translatorComments[1]) || !isset($POFile->references[0])) {
                 throw new Exception('The .po file doesn\'t have valid directives for Processmaker!');
             }
             foreach ($POFile->translatorComments as $a => $aux) {
                 $aux = trim($aux);
                 if ($aux == 'TRANSLATION') {
                     $identifier = $aux;
                 } else {
                     $var = explode('/', $aux);
                     if ($var[0] == 'LABEL') {
                         $context = $aux;
                     }
                     if ($var[0] == 'JAVASCRIPT') {
                         $context = $aux;
                     }
                 }
                 if (preg_match('/^([\\w-]+)\\/([\\w-]+\\/*[\\w-]*\\.xml\\?)/', $aux, $match)) {
                     $identifier = $aux;
                 } else {
                     if (preg_match('/^([\\w-]+)\\/([\\w-]+\\/*[\\w-]*\\.xml$)/', $aux, $match)) {
                         $context = $aux;
                     }
                 }
             }
             $reference = $POFile->references[0];
             // it is a Sql insert on TRANSLATIONS TAble
             if ($identifier == 'TRANSLATION') {
                 if ($updateDB) {
                     list($category, $id) = explode('/', $context);
                     $result = $oTranslation->addTranslation($category, $id, $LOCALE, trim(stripcslashes(str_replace(chr(10), '', $rowTranslation['msgstr']))));
                     if ($result['codError'] == 0) {
                         $countItemsSuccess++;
                     } else {
                         $errorMsg .= $id . ': ' . $result['message'] . "\n";
                     }
                 }
             } elseif ($updateXml) {
                 $xmlForm = $context;
                 //erik: expresion to prevent and hable correctly dropdown values like -1, -2 etc.
                 preg_match('/^([\\w_]+)\\s-\\s([\\w_]+)\\s*-*\\s*([\\w\\W]*)$/', $reference, $match);
                 if (!file_exists(PATH_XMLFORM . $xmlForm)) {
                     $errorMsg .= 'file doesn\'t exist: ' . PATH_XMLFORM . $xmlForm . "\n";
                     continue;
                 }
                 if (count($match) < 4) {
                     $near = isset($rowTranslation['msgid']) ? $rowTranslation['msgid'] : (isset($rowTranslation['msgstr']) ? $rowTranslation['msgstr'] : '');
                     $errorMsg .= "Invalid Translation reference: \"{$reference}\",  near -> " . strip_tags($near) . "\n";
                     continue;
                 }
                 G::LoadSystem('dynaformhandler');
                 $dynaform = new dynaFormHandler(PATH_XMLFORM . $xmlForm);
                 $fieldName = $match[2];
                 $codes = explode('-', $reference);
                 if (sizeof($codes) == 2) {
                     //is a normal node
                     $dynaform->addChilds($fieldName, array($LOCALE => stripcslashes(str_replace(chr(10), '', $rowTranslation['msgstr']))));
                 } elseif (sizeof($codes) > 2) {
                     //is a node child for a language node
                     $name = $match[3] == "''" ? '' : $match[3];
//.........这里部分代码省略.........
开发者ID:ralpheav,项目名称:processmaker,代码行数:101,代码来源:Language.php


注:本文中的Translation::addTranslation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。