예제 #1
0
 /**
  * TuiyoLocalize::initiate()
  * Initiates a language domain
  * @param mixed $domain
  * @param mixed $locale
  * @param mixed $encoding
  * @return
  */
 public function initiate($domain, $locale, $encoding)
 {
     //Initialize gettText
     $locale = !empty($locale) ? $locale : TUIYO_DEFAULT_LOCALE;
     $domain = !empty($domain) ? $domain : 'system';
     $encoding = !empty($encoding) ? $encoding : TUIYO_DEFAULT_ENCODING;
     putenv("LANG={$locale}");
     if (!extension_loaded('gettext')) {
         TuiyoLoader::import("gettext.gettext", "elibrary", "inc");
         T_setlocale(LC_ALL, $locale);
         T_bindtextdomain($domain, TUIYO_LOCALE);
         T_bind_textdomain_codeset($domain, $encoding);
         T_textdomain($domain);
         //return TRUE;
     }
     setlocale(LC_ALL, $locale);
     bindtextdomain($domain, TUIYO_LOCALE);
     bind_textdomain_codeset($domain, $encoding);
     textdomain($domain);
     $path = "components/com_tuiyo/locale/" . $locale;
     //Load the parameters for the site!
     if (!class_exists('JSite')) {
         $path = "../components/com_tuiyo/locale/" . $locale;
     }
     $GLOBALS['mainframe']->addMetaTag("locale", $locale);
     $GLOBALS['mainframe']->addCustomHeadTag('<link href="' . $path . '/LC_MESSAGES/system.client.json" lang="' . $locale . '" rel="gettext" />');
 }
예제 #2
0
파일: i18n.php 프로젝트: Wildboard/WbWebApp
 /**
  * 
  * Initializes the php-gettext
  * Remember to load first php-gettext
  * @param string $locale
  * @param string $charset
  * @param string $domain
  */
 public static function initialize($locale = 'en_UK', $charset = 'utf-8', $domain = 'messages')
 {
     /**
      * setting the statics so later we can access them from anywhere
      */
     //we allow to choose lang from the url
     if (Core::config('i18n.allow_query_language') == 1) {
         if (Core::get('language') !== NULL) {
             $locale = Core::get('language');
         } elseif (Cookie::get('user_language') !== NULL) {
             $locale = Cookie::get('user_language');
         }
         Cookie::set('user_language', $locale, Core::config('auth.lifetime'));
     }
     self::$lang = $locale;
     //used in i18n kohana
     self::$locale = $locale;
     self::$charset = $charset;
     self::$domain = $domain;
     //time zone set in the config
     date_default_timezone_set(Kohana::$config->load('i18n')->timezone);
     //Kohana core charset, used in the HTML templates as well
     Kohana::$charset = self::$charset;
     /**
      * In Windows LC_MESSAGES are not recognized by any reason.
      * So we check if LC_MESSAGES is defined to avoid bugs,
      * and force using gettext
      */
     if (defined('LC_MESSAGES')) {
         $locale_res = setlocale(LC_MESSAGES, self::$locale);
     } else {
         $locale_res = FALSE;
     }
     // used with a function money_format
     setlocale(LC_MONETARY, self::$locale);
     /**
      * check if gettext exists if not uses gettext dropin
      */
     if (!function_exists('_') or $locale_res === FALSE or empty($locale_res)) {
         /**
          * gettext override
          * v 1.0.11
          * https://launchpad.net/php-gettext/
          * We load php-gettext here since Kohana_I18n tries to create the function __() function when we extend it.
          * PHP-gettext already does this.
          */
         require Kohana::find_file('vendor', 'php-gettext/gettext', 'inc');
         T_setlocale(LC_MESSAGES, self::$locale);
         T_bindtextdomain(self::$domain, DOCROOT . 'languages');
         T_bind_textdomain_codeset(self::$domain, self::$charset);
         T_textdomain(self::$domain);
         //force to use the gettext dropin
         self::$dropin = TRUE;
     } else {
         bindtextdomain(self::$domain, DOCROOT . 'languages');
         bind_textdomain_codeset(self::$domain, self::$charset);
         textdomain(self::$domain);
     }
 }
예제 #3
0
파일: locale.php 프로젝트: 5haman/Sendy
function set_locale($locale)
{
    //Set language
    putenv("LC_ALL={$locale}");
    T_setlocale(LC_MESSAGES, $locale);
    T_bindtextdomain('default', 'locale');
    T_bind_textdomain_codeset('default', 'UTF-8');
    T_textdomain('default');
}
예제 #4
0
 function _setlocaleEmu($category, $locale, $baseDir)
 {
     $domain = 'pommo';
     $encoding = 'UTF-8';
     T_setlocale($category, $locale);
     T_bindtextdomain($domain, $baseDir . '/language');
     T_bind_textdomain_codeset($domain, $encoding);
     T_textdomain($domain);
     return true;
 }
예제 #5
0
파일: I18N.php 프로젝트: justvinz/i18n
 /**
  * Sets a locale (if supported)
  * @param String $locale locale to set
  * @param String $domain messages domain
  * @return String locale set
  */
 private static function setLocale($locale, $domain = 'messages')
 {
     $locale = self::isSupported($locale) ? $locale : self::$config['default'];
     T_setlocale(LC_MESSAGES, $locale);
     T_bindtextdomain($domain, self::$config['path']);
     T_bind_textdomain_codeset($domain, self::$config['encoding']);
     T_textdomain($domain);
     header("Content-type: text/html; charset=" . self::$config['encoding']);
     return $locale;
 }
예제 #6
0
 private function set_current_lang($newlang)
 {
     $this->current_lang = $newlang;
     @putenv("LC_ALL=" . $newlang);
     // for WinXP SP3
     T_setlocale(LC_ALL, $newlang);
     T_bindtextdomain("vpsAdmin", WWW_ROOT . "/lang/locale/");
     T_bind_textdomain_codeset("vpsAdmin", "UTF-8");
     T_textdomain("vpsAdmin");
     setcookie(self::c_name, $this->current_lang, time() + 86400 * 7);
 }
예제 #7
0
 /**
  * Class constructor
  *
  * @return	void
  */
 public function __construct()
 {
     $config =& get_config();
     $lang = empty($config['language']) ? $this->fallback : $config['language'];
     T_setlocale(LC_MESSAGES, $lang);
     // Application Language then system's
     T_bindtextdomain('application', APPPATH . 'language');
     T_bindtextdomain('system', BASEPATH . 'language');
     T_bind_textdomain_codeset('application', 'UTF-8');
     T_textdomain('application');
     unset($lang);
     log_message('info', 'Language Class Initialized');
 }
예제 #8
0
파일: i18n.php 프로젝트: axelsimon/ampache
/**
 * load_gettext
 * Sets up our local gettext settings.
 *
 * @return void
 */
function load_gettext()
{
    $lang = AmpConfig::get('lang');
    $charset = AmpConfig::get('site_charset') ?: 'UTF-8';
    $locale = $lang . '.' . $charset;
    //debug_event('i18n', 'Setting locale to ' . $locale, 5);
    T_setlocale(LC_MESSAGES, $locale);
    /* Bind the Text Domain */
    T_bindtextdomain('messages', AmpConfig::get('prefix') . "/locale/");
    T_bind_textdomain_codeset('messages', $charset);
    T_textdomain('messages');
    //debug_event('i18n', 'gettext is ' . (locale_emulation() ? 'emulated' : 'native'), 5);
}
예제 #9
0
 public static function applyLocale($newlocale)
 {
     self::$locale = $newlocale;
     //TODO Allow locale to be overriden by GET request?
     //if($_GET['lang']) $locale = $_GET['lang'];
     locale_set_default(self::$locale);
     //$language = locale_get_display_language(self::$locale, 'en');
     $lang = locale_get_primary_language(self::$locale);
     //$region = locale_get_display_region(self::$locale);
     T_setlocale(LC_MESSAGES, $lang);
     T_bindtextdomain("grase", "/usr/share/grase/locale");
     T_bind_textdomain_codeset("grase", "UTF-8");
     T_textdomain("grase");
 }
예제 #10
0
/**
 * Define language for get-text translator
 *
 * Directory structure for traduction must be:
 *		./locale/Lang/LC_MESSAGES/messages.mo
 * Example (French):
 *		./locale/fr_FR/LC_MESSAGES/messages.mo
 */
function defineLanguage($lang)
{
    $encoding = 'UTF-8';
    if (isset($lang)) {
        $locale = $lang;
    } else {
        $locale = DEFAULT_LOCALE;
    }
    // gettext setup
    T_setlocale(LC_MESSAGES, $locale);
    // Set the text domain as 'messages'
    $domain = 'messages';
    T_bindtextdomain($domain, LOCALE_DIR);
    T_bind_textdomain_codeset($domain, $encoding);
    T_textdomain($domain);
}
예제 #11
0
 /**
  * Define language for get-text translator
  *
  * Directory structure for the translation must be:
  *		./app/locale/Lang/LC_MESSAGES/messages.mo
  * Example (French):
  *		./app/locale/fr_FR/LC_MESSAGES/messages.mo
  */
 public static function setLanguage($lang = 'en_EN')
 {
     $encoding = 'UTF-8';
     $languages = parse_ini_file(CONF_LANG_INI);
     if (isset($lang) && in_array($lang, $languages)) {
         $locale = $lang;
     } else {
         $locale = CONF_DEFAULT_LOCALE;
     }
     // gettext setup
     T_setlocale(LC_MESSAGES, $locale);
     // Set the text domain as 'messages'
     $domain = 'messages';
     T_bindtextdomain($domain, LOCALE_DIR);
     T_bind_textdomain_codeset($domain, $encoding);
     T_textdomain($domain);
 }
예제 #12
0
 /**
  * Class Constructor
  *
  * @param	String			$type		Type of language-file
  * @author	Lars Michelsen <*****@*****.**>
  */
 public function __construct($textDomain = 'nagvis')
 {
     $this->textDomain = $textDomain;
     // Append encoding (UTF8)
     $this->sCurrentEncoding = 'UTF-8';
     // Check for gettext extension
     require_once 'gettext.inc';
     $this->setLanguage();
     T_bindtextdomain($this->textDomain, cfg('paths', 'language'));
     T_bind_textdomain_codeset($this->textDomain, $this->sCurrentEncoding);
     T_textdomain($this->textDomain);
     // Check if native gettext or php-gettext is used
     if (DEBUG && DEBUGLEVEL & 2) {
         if (locale_emulation()) {
             debug('GlobalLanguage: Using php-gettext for translations');
         } else {
             debug('GlobalLanguage: Using native gettext for translations');
         }
     }
 }
예제 #13
0
/**
 * displayNoConfig 
 * 
 * @return void
 */
function displayNoConfig()
{
    include_once 'inc/constants.php';
    include_once 'inc/thirdparty/gettext.inc';
    // Setup php-gettext
    T_setlocale(LC_MESSAGES, 'en_US');
    T_bindtextdomain('messages', './language');
    T_bind_textdomain_codeset('messages', 'UTF-8');
    T_textdomain('messages');
    displayHeader(false);
    echo '
    <div id="oops">
        <h1>' . T_('Oops!') . '</h1>
        <p>
            ' . T_('This site hasn\'t been installed yet.') . ' 
            <a href="install.php">' . T_('You must finish the installation before using the site.') . '</a>
        </p>
    </div>
</body>
</html>';
}
예제 #14
0
 /**
  * loadTextDomain
  *
  * This loads a new domain with a certain path into the domain table.
  *
  * Note: gettext paths
  *
  * Give a path/to/your/mo/files without LC_MESSAGES and locale!
  *
  * If you use: T_bindtextdomain('clansuite', '/html/locales');
  * The mo.file would be looked up in /html/locales/de_DE/LC_MESSAGES/clansuite.mo
  * The $domain string specifies the mo-filename => "$domain.mo"
  * So if $domain = 'clansuite'; => clansuite.mo
  *
  * @link http://www.php.net/function.bindtextdomain
  */
 public function loadTextDomain($category, $domain, $locale, $module = null)
 {
     #Koch_Debug::firebug($module);
     // if, $locale string is not over 3 chars long -> $locale = "en", build "en_EN"
     if (isset($locale[3]) == false) {
         $locale = mb_strtolower($locale) . '_' . mb_strtoupper($locale);
     }
     // Environment Variable LANGUAGE has priority above any local setting
     putenv('LANGUAGE=' . $locale);
     putenv('LANG=' . $locale);
     setlocale(LC_ALL, $locale . '.UTF-8');
     T_setlocale(LC_ALL, $locale . '.UTF8', $locale);
     /**
      * Set the domain_directory (where look for MO files named $domain.po)
      */
     if ($module === null) {
         // for domain 'clansuite', it's the ROOT_LANGUAGES directory
         $domain_directory = ROOT_LANGUAGES;
     } else {
         // set a specific module directory
         $domain_directory = ROOT_MOD . $module . DIRECTORY_SEPARATOR . 'languages';
     }
     // Set the Domain
     T_bindtextdomain($domain, $domain_directory);
     T_bind_textdomain_codeset($domain, $this->encoding);
     T_textdomain($domain);
     #Koch_Debug::firebug('<p>Textdomain "' .$domain .'" loaded from path "'. $domain_directory .'" for "'. $module .'"</p>');
     return true;
 }
예제 #15
0
 function setLocale($locale, $charset = null)
 {
     $this->locale = $locale;
     if (!$charset) {
         $charset = $this->charset;
     }
     putenv("LC_ALL={$locale}");
     T_setlocale(LC_ALL, $locale);
     //echo $this->locale_dir;
     //if (!is_dir($this->locale_dir))
     //throw new Exception('Cannot find Locale message path');
     T_bindtextdomain("messages", $this->locale_dir);
     T_bind_textdomain_codeset('messages', $charset);
     T_textdomain("messages");
 }
예제 #16
0
파일: define.php 프로젝트: evazzadeh/Saloos
 public function __construct()
 {
     // check php version to upper than 5.6
     if (version_compare(phpversion(), '5.6', '<')) {
         die("<p>For using Saloos you must update php version to 5.6 or higher!</p>");
     }
     /**
      * in coming soon period show public_html/pages/coming/ folder
      * developer must set get parameter like site.com/dev=anyvalue
      * for disable this attribute turn off it from config.php in project root
      */
     if (defined('CommingSoon') && CommingSoon && isset($_GET['dev'])) {
         setcookie('preview', 'yes', time() + 30 * 24 * 60 * 60, '/', '.' . Service);
     } elseif (defined("CommingSoon") && CommingSoon && !isset($_COOKIE["preview"])) {
         header('Location: http://' . AccountService . MainTld . '/static/page/coming/', true, 302);
         exit;
     }
     /**
      * Localized Language, defaults to English.
      *
      * Change this to localize Saloos. A corresponding MO file for the chosen
      * language must be installed to content/languages. For example, install
      * fa_IR.mo to content/languages and set LANGUAGE to 'fa_IR' to enable Persian
      * language support.
      */
     if (router::get_storage('language')) {
         switch (Tld) {
             case 'ir':
                 router::set_storage('language', "fa_IR");
                 break;
             default:
                 break;
         }
         // do nothing
     } elseif (isset($_GET["lang"]) && router::get_repository_name() !== 'content') {
         router::set_storage('language', $_GET["lang"]);
     } elseif (isset($_COOKIE["lang"])) {
         router::set_storage('language', $_COOKIE["lang"]);
     } else {
         router::set_storage('language', router::get_storage('defaultLanguage'));
     }
     // save language preference for future page requests
     setcookie('lang', router::get_storage('language'), time() + 30 * 24 * 60 * 60, '/', '.' . Service);
     // use saloos php gettext function
     require_once lib . 'utility/gettext/gettext.inc';
     // gettext setup
     T_setlocale(LC_MESSAGES, router::get_storage('language'));
     // Set the text domain as 'messages'
     T_bindtextdomain('messages', root . 'includes/languages');
     T_bind_textdomain_codeset('messages', 'UTF-8');
     T_textdomain('messages');
     // check direction of language and set for rtl languages
     switch (router::get_storage('language')) {
         case 'fa_IR':
         case 'ar_SU':
             router::set_storage('direction', 'rtl');
             break;
         default:
             router::set_storage('direction', 'ltr');
             break;
     }
     /**
      * If DEBUG is TRUE you can see the full error description, If set to FALSE show userfriendly messages
      * change it from project config.php
      */
     if (!defined('DEBUG')) {
         define('DEBUG', false);
     }
     if (DEBUG) {
         ini_set('display_errors', 'On');
         ini_set('display_startup_errors', 'On');
         ini_set('error_reporting', 'E_ALL | E_STRICT');
         ini_set('track_errors', 'On');
         ini_set('display_errors', 1);
         error_reporting(E_ALL);
         //Setting for the PHP Error Handler
         // set_error_handler('\lib\error::myErrorHandler');
         //Setting for the PHP Exceptions Error Handler
         // set_exception_handler('\lib\error::myErrorHandler');
         //Setting for the PHP Fatal Error
         // register_shutdown_function('\lib\error::myErrorHandler');
     } else {
         error_reporting(0);
         ini_set('display_errors', 0);
     }
     // change header and remove php from it
     header("X-Powered-By: Saloos!");
     /**
      * A session is a way to store information (in variables) to be used across multiple pages.
      * Unlike a cookie, the information is not stored on the users computer.
      * access to session with this code: $_SESSION["test"]
      */
     if (is_string(Domain)) {
         session_name(Domain);
     }
     session_set_cookie_params(0, '/', '.' . Service, false, true);
     session_start();
 }
예제 #17
0
 private function _setLocaleConfig()
 {
     $config = array('locale' => $this->getUserLocale(), 'lang' => $this->getUserLang(), 'encoding' => 'UTF-8', 'encoding_light' => 'utf8', 'domain' => $this->getUserLang(), 'path' => realpath('./lang'));
     if (self::_getTextMode() == self::GETTEXT_MODE_NATIVE) {
         putenv("LANG=" . $config["locale"] . '.' . $config["encoding_light"]);
         putenv("LC_ALL=" . $config["locale"] . '.' . $config["encoding_light"]);
         putenv("LANGUAGE=" . $config["locale"] . '.' . $config["encoding_light"]);
         setlocale(LC_ALL, $config["locale"] . '.' . $config["encoding_light"]);
         bindtextdomain($config["domain"], $config["path"]);
         bind_textdomain_codeset($config["domain"], $config["encoding"]);
         textdomain($config["domain"]);
     } else {
         require_once 'gettext.inc';
         T_setlocale(LC_MESSAGES, $config['locale']);
         T_bindtextdomain($config['domain'], LOCALE_PATH);
         T_bind_textdomain_codeset($config['domain'], $config['encoding']);
         T_textdomain($config['domain']);
     }
     return true;
 }
예제 #18
0
    $lang = preg_split('#[,;]#', $lang);
    return lang_normalize($lang[0]);
}
/* Init i18n */
$detected_lang = request_lang();
$ll = substr($detected_lang, 0, 2);
// moved into request_lang()
//if (isset($lang_rewrite[$detected_lang]))
//	$detected_lang=$lang_rewrite[$detected_lang];
T_setlocale(LC_ALL, $detected_lang);
T_bindtextdomain('site', rtrim(BU_LANG_PATH, DIRECTORY_SEPARATOR));
T_bind_textdomain_codeset('site', 'UTF8');
T_bindtextdomain('update', rtrim(BU_LANG_PATH, DIRECTORY_SEPARATOR));
T_bind_textdomain_codeset('update', 'UTF8');
T_bindtextdomain('update-legacy', rtrim(BU_LANG_PATH, DIRECTORY_SEPARATOR));
T_bind_textdomain_codeset('update-legacy', 'UTF8');
T_bindtextdomain('customize', rtrim(BU_LANG_PATH, DIRECTORY_SEPARATOR));
T_bind_textdomain_codeset('customize', 'UTF8');
T_textdomain('update');
$newtrans = true;
if (strpos("xx,ja,sl,id,uk,rm,da,sv,hu,fa,gl", $ll) > 0) {
    $newtrans = false;
}
//if (!$newtrans)
//    T_textdomain('browser-update');
//var_dump($CURRENTLOCALE);
//var_dump($EMULATEGETTEXT);
//var_dump(request_lang());
//var_dump(setlocale(LC_ALL, 'de_DE'));
//$EMULATEGETTEXT=0;
//var_dump(setlocale(LC_MESSAGES, 'deutsch'));
예제 #19
0
<?php

$langPlug = array("fr" => "fr_FR.utf8", "en" => "en_US", "es" => "es_ES.utf8");
//
if (isset($langPlug[$lang]) && $langPlug[$lang]) {
    require_once dirname(__FILE__) . '/../../../includes/lang/php-gettext/gettext.inc';
    T_setlocale(LC_MESSAGES, $langPlug[$lang]);
    T_bindtextdomain("comment", dirname(__FILE__));
    T_bind_textdomain_codeset("comment", "UTF-8");
    T_textdomain("comment");
}
예제 #20
0
파일: i18n.inc.php 프로젝트: fg-ok/codev
    // Try many values because OS doesn't have the same constants
    $phpLocale = setlocale(LC_ALL, "it_IT", "it", "Italian");
} else {
    // No locale set, it's because visitors modify the url, so forbidden reply
    header('HTTP/1.1 403 Forbidden');
    exit;
}
T_setlocale(LC_ALL, $phpLocale);
$_SESSION['locale'] = $locale;
// we want 3.5 always to be displayed '3.5' and not '3,5'
$phpLocale = setlocale(LC_NUMERIC, "en_US", "us", "usa", "en", "eng", "English");
T_setlocale(LC_NUMERIC, $phpLocale);
$locales_dir = TRUE === file_exists('./i18n/locale') ? './i18n/locale' : ($locales_dir = '../i18n/locale');
$textdomain = "codev";
T_bindtextdomain($textdomain, $locales_dir);
T_bind_textdomain_codeset($textdomain, 'UTF-8');
T_textdomain($textdomain);
$availableEncoding = mb_detect_order();
if (!array_search("ISO-8859-1", $availableEncoding)) {
    $newEnconding = array();
    $newEnconding[] = "ISO-8859-1";
    mb_detect_order(array_merge($availableEncoding, $newEnconding));
}
/**
 * Get the user locale, choose in this order :
 * -> The locale from GET url
 * -> The locale set into the SESSION
 * -> The prefered existing locale of the browser
 * @return string The locale
 */
function getLocale()
예제 #21
0
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 * @category  FCMS
 * @package   FamilyConnections
 * @author    Ryan Haudenschilt <*****@*****.**> 
 * @copyright 2007 Haudenschilt LLC
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GPLv2
 * @link      http://www.familycms.com/wiki/
 */
require_once 'inc/thirdparty/gettext.inc';
require_once 'inc/constants.php';
// Setup php-gettext
T_setlocale(LC_MESSAGES, 'en_US');
T_bindtextdomain('messages', './language');
T_bind_textdomain_codeset('messages', 'UTF-8');
T_textdomain('messages');
// Fix magic quotes
if (get_magic_quotes_gpc()) {
    $_REQUEST = array_map('stripslashes', $_REQUEST);
    $_GET = array_map('stripslashes', $_GET);
    $_POST = array_map('stripslashes', $_POST);
    $_COOKIE = array_map('stripslashes', $_COOKIE);
}
define('URL_PREFIX', '');
define('GALLERY_PREFIX', 'gallery/');
main();
return;
/**
 * main 
 * 
예제 #22
0
파일: fcms.php 프로젝트: lmcro/fcms
/**
 * setLanguage 
 * 
 * Sets the language for the script.  Sets up php-gettext.
 * 
 * @return void
 */
function setLanguage()
{
    if (isset($_SESSION['language'])) {
        T_setlocale(LC_MESSAGES, $_SESSION['language']);
    } else {
        $lang = getLanguage();
        T_setlocale(LC_MESSAGES, $lang);
    }
    T_bindtextdomain('messages', './language');
    T_bind_textdomain_codeset('messages', 'UTF-8');
    T_textdomain('messages');
}
예제 #23
0
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
// define constants
define(PROJECT_DIR, realpath('./'));
define(LOCALE_DIR, PROJECT_DIR . '/locale');
define(DEFAULT_LOCALE, 'en_US');
require_once '../gettext.inc';
$supported_locales = array('en_US', 'sr_CS', 'de_CH');
$encoding = 'UTF-8';
$locale = isset($_GET['lang']) ? $_GET['lang'] : DEFAULT_LOCALE;
// gettext setup
T_setlocale(LC_MESSAGES, $locale);
// Set the text domain as 'messages'
$domain = 'messages';
T_bindtextdomain($domain, LOCALE_DIR);
T_bind_textdomain_codeset($domain, $encoding);
T_textdomain($domain);
header("Content-type: text/html; charset={$encoding}");
?>
<html>
<head>
<title>PHP-gettext fallback example</title>
</head>
<body>
<h1>PHP-gettext as a fallback solution</h1>
<p>Example showing how to use PHP-gettext as a fallback solution if the native gettext library is not available or the system does not support the requested locale.</p>

<?php 
print "<p>";
foreach ($supported_locales as $l) {
    print "[<a href=\"?lang={$l}\">{$l}</a>] ";
예제 #24
0
function includeTranslation($locale, $domain)
{
    T_setlocale(LC_MESSAGES, $locale);
    T_bindtextdomain($domain, JAPPIX_BASE . '/i18n');
    T_bind_textdomain_codeset($domain, 'UTF-8');
    T_textdomain($domain);
}
예제 #25
0
 * @param array The elements in the array to translate
 * @return The array with the elements translated
 */
function translate_array(&$a, $b)
{
    foreach ($a as &$row) {
        foreach ($b as $el) {
            if (isset($row[$el])) {
                $row[$el] = T_($row[$el]);
            }
        }
    }
}
/**
 * Translate then quote a string to make it ready
 * for database insertion
 *
 * @param string $msg The message to translate and quote
 * @return string The translated message quoted
 */
function TQ_($msg)
{
    $msg = T_($msg);
    $msg = str_replace(array('\\', ""), array('\\\\', "\\"), $msg);
    return str_replace("'", "\\'", $msg);
}
$locale = isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) ? substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2) : DEFAULT_LOCALE;
T_setlocale(LC_MESSAGES, $locale);
T_bindtextdomain($locale, dirname(__FILE__) . "/locale");
T_bind_textdomain_codeset($locale, 'UTF-8');
T_textdomain($locale);
예제 #26
0
파일: core.php 프로젝트: carriercomm/Nuance
function loadLocale($domain, $locale = null)
{
    define('PROJECT_DIR', realpath('./'));
    define('LOCALE_DIR', PROJECT_DIR . '/../locale');
    require_once 'gettext/gettext.inc';
    $encoding = 'UTF-8';
    if (!$locale) {
        $locale = configgetvalue('system', 'main', NULL, $domain . 'Locale');
    }
    T_setlocale(LC_MESSAGES, $locale);
    T_bindtextdomain($domain, LOCALE_DIR);
    T_bind_textdomain_codeset($domain, $encoding);
    T_textdomain($domain);
}
예제 #27
0
파일: index.php 프로젝트: zmellal/alfanous
        $this->json; # decoded JSON
        $this->nb_pages; # number of pages
        $this->page_nb; # current page number
        $this->hit_page_limit; # boolian flag for page limit (currently 100 pages)
        $this->rtl; # boolian flag for RTL language
        */
    }
}
$mv = new MV();
# Gettext
# set language
putenv("LC_ALL={$mv->language}");
T_setlocale(LC_ALL, $mv->language);
# set local
T_bindtextdomain($mv->domain, LOCALE_DIR);
T_bind_textdomain_codeset($mv->domain, $mv->encoding);
T_textdomain($mv->domain);
# import localized texts
require_once "./mobiletext.php";
$mt = new MT();
# add direction variable
$mv->rtl = $mt->DIR == "rtl" ? True : False;
# HTTP header
header("Content-Type: application/xhtml+xml; charset=UTF-8");
header("Content-Language: ar");
header("Cache-Control: max-age=3600, must-revalidate");
header(sprintf("Last-Modified: %s", date("r", filemtime($_SERVER['SCRIPT_FILENAME']))));
# Query JSON service
if ($mv->search) {
    # JSON query
    $handle = fopen($mv->query_site . $mv->query_search . $mv->query_page . $mv->query_string . $mv->query_fuzzy, "rb");
예제 #28
0
 private function initializeLocalization()
 {
     $locale = self::getLocale();
     require_once PATH_ROOT . 'lib/gettext/gettext.inc';
     $domain = "messages";
     T_setlocale(LC_ALL, $locale . '.UTF-8', $locale);
     T_bindtextdomain($domain, PATH_ROOT . 'locale/');
     T_bind_textdomain_codeset($domain, 'UTF-8');
     T_textdomain($domain);
     if (!ini_get("safe_mode")) {
         @putenv("LC_ALL={$locale}.utf8");
     }
     define('LOCALE', $locale);
     define('LANG', substr($locale, 0, 2));
 }
예제 #29
0
 /**
  * loads gettexts or droppin
  * @param  string $locale  
  * @param  string $domain  
  * @param  string $charset 
  */
 private static function gettext_init($locale, $domain = 'messages', $charset = 'utf8')
 {
     /**
      * check if gettext exists if not uses gettext dropin
      */
     $locale_res = setlocale(LC_ALL, $locale);
     if (!function_exists('_') or $locale_res === FALSE or empty($locale_res)) {
         /**
          * gettext override
          * v 1.0.11
          * https://launchpad.net/php-gettext/
          * We load php-gettext here since Kohana_I18n tries to create the function __() function when we extend it.
          * PHP-gettext already does this.
          */
         include APPPATH . 'common/vendor/php-gettext/gettext.inc';
         T_setlocale(LC_ALL, $locale);
         T_bindtextdomain($domain, DOCROOT . 'languages');
         T_bind_textdomain_codeset($domain, $charset);
         T_textdomain($domain);
     } else {
         bindtextdomain($domain, DOCROOT . 'languages');
         bind_textdomain_codeset($domain, $charset);
         textdomain($domain);
         function __($msgid)
         {
             return _($msgid);
         }
     }
 }
예제 #30
0
 function msg($msgid, $lang = "")
 {
     T_setlocale(LC_ALL, $this->getLang($lang));
     T_bindtextdomain($this->domain, $this->directory);
     T_textdomain($this->domain);
     T_bind_textdomain_codeset($this->domain, 'UTF-8');
     if ($msgid == "") {
         return "";
     } else {
         return T_gettext($msgid);
     }
 }