/**
  * Method will setup Internationalization.
  * NOTE: This method has been INTENTIONALLY left incomplete.
  * @return void
  */
 public static function InitializeI18n()
 {
     if (isset($_SESSION)) {
         if (array_key_exists('country_code', $_SESSION)) {
             QApplication::$CountryCode = $_SESSION['country_code'];
         }
         if (array_key_exists('language_code', $_SESSION)) {
             QApplication::$LanguageCode = $_SESSION['language_code'];
         }
     }
     /*
      * NOTE: This is where you would implement code to do Language Setting discovery, as well, for example:
      *   Checking against $_GET['language_code']
      *   checking against session (example provided below)
      *   Checking the URL
      *   etc.
      * Options to do this are left to the developer.
      */
     // Initialize I18n if QApplication::$LanguageCode is set
     if (QApplication::$LanguageCode) {
         QI18n::Initialize();
     } else {
         // QApplication::$CountryCode = 'us';
         // QApplication::$LanguageCode = 'en';
         // QI18n::Initialize();
     }
 }
Exemple #2
0
 protected function button_Click($strFormId, $strControlId, $strParameter)
 {
     // NORMALLY -- these settings are setup in prepend.inc
     // But it is pulled out here to illustrate
     $_SESSION['language_code'] = $strParameter;
     // In order for I18n Translation to be enabled, you must have a language code
     // defined and the QI18n object must be initialized
     QApplication::$LanguageCode = $strParameter;
     QI18n::Initialize();
 }
 protected function Form_Create()
 {
     // let's change translation class
     require_once 'sample_translator.class.php';
     QI18n::$DefaultTranslationClass = 'QSampleTranslation';
     // Set default language to French
     QApplication::$LanguageCode = 'fr';
     QApplication::$CountryCode = null;
     QI18n::Initialize();
 }
Exemple #4
0
 /**
  * If LanguageCode is specified and QI18n::Initialize() has been called, then this
  * will perform a translation of the given token for the specified Language Code and optional
  * Country code.
  *
  * Otherwise, this will simply return the token as is.
  * This method is also used by the global print-translated "_t" function.
  *
  * @param string $strToken
  * @return string the Translated token (if applicable)
  */
 public static function Translate($strToken)
 {
     if (QApplication::$LanguageObject) {
         return QApplication::$LanguageObject->TranslateToken($strToken);
     } else {
         return $strToken;
     }
 }
Exemple #5
0
    // Start Session Handler (if required)
    /////////////////////////////
    //session_set_cookie_params(2);
    session_start();
    //////////////////////////////////////////////
    // Setup Internationalization and Localization (if applicable)
    // Note, this is where you would implement code to do Language Setting discovery, as well, for example:
    // * Checking against $_GET['language_code']
    // * checking against session (example provided below)
    // * Checking the URL
    // * etc.
    // TODO: options to do this are left to the developer
    //////////////////////////////////////////////
    if (isset($_SESSION)) {
        if (array_key_exists('country_code', $_SESSION)) {
            QApplication::$CountryCode = $_SESSION['country_code'];
        }
        if (array_key_exists('language_code', $_SESSION)) {
            QApplication::$LanguageCode = $_SESSION['language_code'];
        }
    }
    QApplication::$LanguageCode = 'zh_cn';
    // Initialize I18n if QApplication::$LanguageCode is set
    if (QApplication::$LanguageCode) {
        QI18n::Initialize();
    } else {
        // QApplication::$CountryCode = 'us';
        // QApplication::$LanguageCode = 'en';
        // QI18n::Initialize();
    }
}
Exemple #6
0
 public function tearDown()
 {
     // let's restore translation class, so that other tests use the default one
     QI18n::$DefaultTranslationClass = 'QTranslationPoParser';
 }
Exemple #7
0
 public static function InitializeTranslationEngine()
 {
     require_once __NARRO_INCLUDES__ . '/gettext_reader.class.php';
     require_once __NARRO_INCLUDES__ . '/StreamReader.class.php';
     if (QApplication::$User->UserId == NarroUser::ANONYMOUS_USER_ID) {
         QApplication::$LanguageCode = QApplication::$TargetLanguage->LanguageCode;
     } else {
         QApplication::$LanguageCode = QApplication::$User->GetPreferenceValueByName('Application language');
     }
     define('__LOCALE_DIRECTORY__', __DOCROOT__ . __SUBDIRECTORY__ . '/locale/' . QApplication::$LanguageCode);
     QI18n::Initialize('NarroPoParser');
 }
<div id="demoZone">
	<h2>Translations made using the custom QSampleTranslation class</h2>
    <h3>French <small>(default set in <code>Form_Create()</code>)</small></h3>
    <ul>
        <li>Required -> <?php 
_t('Required');
?>
</li>
        <li>Optional -> <?php 
_t('Optional');
?>
</li>
    </ul>
    <h3><strong>Spanish</strong></h3>
    <?php 
$i18n = QI18n::Load('es');
?>
    <ul>
        <li>Required -> <?php 
echo $i18n->TranslateToken('Required');
?>
</li>
        <li>Optional -> <?php 
echo $i18n->TranslateToken('Optional');
?>
</li>
    </ul>
</div>

<?php 
$this->RenderEnd();
Exemple #9
0
 protected function ParsePoData($strPoData)
 {
     $strPoData = str_replace("\r", '', trim($strPoData));
     $strPoLines = explode("\n", $strPoData);
     $strMatches = array();
     $intState = QI18n::PoParseStateNone;
     $intLineCount = count($strPoLines);
     if (strlen($strPoLines[0]) == 0) {
         return;
     }
     for ($intLineNumber = 0; $intLineNumber < $intLineCount; $intLineNumber++) {
         $strPoLine = $strPoLines[$intLineNumber] = trim($strPoLines[$intLineNumber]);
         if (strlen($strPoLine) && QString::FirstCharacter($strPoLine) != '#') {
             switch ($intState) {
                 case QI18n::PoParseStateNone:
                     $intCount = preg_match_all('/msgid(_[a-z0-9]+)?[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         $intLineNumber--;
                         $intState = QI18n::PoParseStateMessageIdStart;
                     } else {
                         throw new QPoParserException('Invalid content for PoParseStateNone on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                     }
                     break;
                 case QI18n::PoParseStateMessageIdStart:
                     $intCount = preg_match_all('/msgid(_[a-z0-9]+)?[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         $strMessageId = array('', '', '', '', '', '', '');
                         $strMessageString = array('', '', '', '', '', '', '');
                         $intArrayIndex = 0;
                         $strContent = QI18n::UnescapeContent($strMatches[2][0]);
                         if ($strContent === false) {
                             throw new QPoParserException('Invalid content on Line ' . ($intLineNumber + 1));
                         }
                         $strMessageId[$intArrayIndex] = $strContent;
                         $intState = QI18n::PoParseStateMessageId;
                     } else {
                         throw new QPoParserException('Invalid content for PoParseStateMessageIdStart on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                     }
                     break;
                 case QI18n::PoParseStateMessageId:
                     $intCount = preg_match_all('/msgid(_[a-z0-9]+)[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         if (strlen(trim($strMessageId[$intArrayIndex])) == 0) {
                             throw new QPoParserException('No MsgId content for current MsgId on Line ' . $intLineNumber . ': ' . $strPoLine);
                         }
                         $intArrayIndex++;
                         $strContent = QI18n::UnescapeContent($strMatches[2][0]);
                         if ($strContent === false) {
                             throw new QPoParserException('Invalid content on Line ' . ($intLineNumber + 1));
                         }
                         $strMessageId[$intArrayIndex] = $strContent;
                         break;
                     }
                     $intCount = preg_match_all('/"([\\S 	]*)"/', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         $strContent = QI18n::UnescapeContent($strMatches[1][0]);
                         if ($strContent === false) {
                             throw new QPoParserException('Invalid content on Line ' . ($intLineNumber + 1));
                         }
                         $strMessageId[$intArrayIndex] .= $strContent;
                         break;
                     }
                     $intCount = preg_match_all('/msgstr(\\[[0-9]+\\])?[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         if (strlen(trim($strMessageId[$intArrayIndex])) == 0) {
                             throw new QPoParserException('No MsgId content for current MsgId on Line ' . $intLineNumber . ': ' . $strPoLine);
                         }
                         $intLineNumber--;
                         $intState = QI18n::PoParseStateMessageStringStart;
                         break;
                     }
                     throw new QPoParserException('Invalid content for PoParseStateMessageId on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                 case QI18n::PoParseStateMessageStringStart:
                     $intCount = preg_match_all('/msgstr(\\[[0-9]+\\])?[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         $intArrayIndex = 0;
                         if (strlen($strMatches[1][0])) {
                             $intArrayIndex = intval(substr($strMatches[1][0], 1, strlen($strMatches[1][0]) - 2));
                         }
                         $strContent = QI18n::UnescapeContent($strMatches[2][0]);
                         if ($strContent === false) {
                             throw new QPoParserException('Invalid content on Line ' . ($intLineNumber + 1));
                         }
                         $strMessageString[$intArrayIndex] = $strContent;
                         $intState = QI18n::PoParseStateMessageString;
                     } else {
                         throw new QPoParserException('Invalid content for PoParseStateMessageStringStart on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                     }
                     break;
                 case QI18n::PoParseStateMessageString:
                     $intCount = preg_match_all('/msgid(_[a-z0-9]+)?[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         for ($intIndex = 0; $intIndex < count($strMessageId); $intIndex++) {
                             if (strlen(trim($strMessageId[$intIndex]))) {
                                 if (!strlen(trim($strMessageString[$intIndex]))) {
                                     $this->SetTranslation($strMessageId[$intIndex], "");
                                 }
                                 $this->SetTranslation($strMessageId[$intIndex], $strMessageString[$intIndex]);
                             }
                         }
                         $intLineNumber--;
                         $intState = QI18n::PoParseStateMessageIdStart;
                         break;
                     }
                     $intCount = preg_match_all('/"([\\S 	]*)"/', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         $strContent = QI18n::UnescapeContent($strMatches[1][0]);
                         if ($strContent === false) {
                             throw new QPoParserException('Invalid content on Line ' . ($intLineNumber + 1));
                         }
                         $strMessageString[$intArrayIndex] .= $strContent;
                         break;
                     }
                     $intCount = preg_match_all('/msgstr(\\[[0-9]+\\])?[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         if (strlen($strMatches[1][0])) {
                             $intArrayIndex = intval(substr($strMatches[1][0], 1, strlen($strMatches[1][0]) - 2));
                         } else {
                             throw new QPoParserException('No index specified for alternate MsgStr for PoParseStateMessageString on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                         }
                         if (strlen(trim($strMessageId[$intArrayIndex])) == 0) {
                             throw new QPoParserException('No MsgId for MsgStr' . $strMatches[1][0] . ' for PoParseStateMessageString on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                         }
                         $strContent = QI18n::UnescapeContent($strMatches[2][0]);
                         if ($strContent === false) {
                             throw new QPoParserException('Invalid content on Line ' . ($intLineNumber + 1));
                         }
                         $strMessageString[$intArrayIndex] = $strContent;
                         break;
                     }
                     throw new QPoParserException('Invalid content for PoParseStateMessageString on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                 default:
                     throw new QPoParserException('Invalid PoParseState on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
             }
         }
     }
     for ($intIndex = 0; $intIndex < count($strMessageId); $intIndex++) {
         if (strlen(trim($strMessageId[$intIndex]))) {
             if (!strlen(trim($strMessageString[$intIndex]))) {
                 $this->SetTranslation($strMessageId[$intIndex], "");
             }
             $this->SetTranslation($strMessageId[$intIndex], $strMessageString[$intIndex]);
         }
     }
 }