Revision: 60266
Updated Code
at October 29, 2012 05:53 by chatelao
Updated Code
<?php $locale = "fa"; // Define location and domain of translations $directory = realpath('./') .'/translations/LOCALES'; $domain = 'php-addressbook'; $default_locale = $locale; $supported_locales = array($locale); // Prepare "php-gettext" require_once('gettext/gettext.inc'); // Prepare "native gettext" setup T_setlocale(LC_ALL, $locale); T_bindtextdomain($domain, $directory); T_textdomain($domain); T_bind_textdomain_codeset($domain, 'UTF-8'); echo T_gettext('ADDRESS'); if (!locale_emulation()) { print "<p>locale '$locale' is supported by your system, using native gettext implementation.</p>\n"; } else { print "<p>locale '$locale' is _not_ supported on your system, using the default locale '". $default_locale ."'.</p>\n"; } ?>
Revision: 60265
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 29, 2012 01:49 by chatelao
Initial Code
<?php error_reporting(E_ALL | E_STRICT); $locale = "fa"; // // Define location and domain of translations // $directory = realpath('./') .'/translations/LOCALES'; $domain = 'php-addressbook'; $default_locale = "en"; // // Prepare "native gettext" // putenv("LANG=".$locale); setlocale(LC_ALL, $locale); bindtextdomain($domain, $directory); textdomain($domain); if(function_exists('bind_textdomain_codeset')) { bind_textdomain_codeset($domain, 'UTF-8'); } textdomain($domain); // // Prepare "php-gettext" // require_once('gettext/gettext.inc'); define('PROJECT_DIR', realpath('./')); define('LOCALE_DIR', $directory); define('DEFAULT_LOCALE', $default_locale); echo gettext('ADDRESS'); ?>
Initial URL
Initial Description
Works, even if a locale is not avaliable on the system.
Initial Title
PHP gettext with fallback for native not supported languages
Initial Tags
php
Initial Language
PHP