Exemplo n.º 1
0
 /**
  * get already existing instance, make new instance or throw an exception
  * @return I18n
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new I18n();
     }
     return self::$instance;
 }
Exemplo n.º 2
0
 /**
  * Initializing I18n
  *
  * @param string $dir Plugins directory
  */
 public static function init($locale)
 {
     if (!isset(self::$instance)) {
         self::$instance = new I18n($locale);
     }
     return self::$instance;
 }
Exemplo n.º 3
0
 /**
  * Retorna a instância da classes (padrão singleton)
  * @return	object				retorna a instância de I18n
  */
 public static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new self(Config::get('default_lang'));
     }
     return self::$instance;
 }
Exemplo n.º 4
0
 /**
  * Initialization.
  */
 static function gallery_ready()
 {
     user::load_user();
     $locale = user::active()->locale;
     if (!empty($locale)) {
         // TODO(andy_st): Check session data as well.
         I18n::instance()->locale($locale);
     }
 }
Exemplo n.º 5
0
 public function setup()
 {
     $config = array('root_locale' => 'en', 'default_locale' => 'te_ST', 'locale_dir' => VARPATH . 'locale/');
     $this->i18n = I18n::instance($config);
     ORM::factory("incoming_translation")->where("locale", "te_ST")->delete_all();
     $messages_te_ST = array(array('Hello world', 'Hallo Welt'), array(array('one' => 'One item has been added', 'other' => '%count elements have been added'), array('one' => 'Ein Element wurde hinzugefuegt.', 'other' => '%count Elemente wurden hinzugefuegt.')), array('Hello %name, how are you today?', 'Hallo %name, wie geht es Dir heute?'));
     foreach ($messages_te_ST as $data) {
         list($message, $translation) = $data;
         $entry = ORM::factory("incoming_translation");
         $entry->key = I18n::get_message_key($message);
         $entry->message = serialize($message);
         $entry->translation = serialize($translation);
         $entry->locale = 'te_ST';
         $entry->revision = null;
         $entry->save();
     }
 }
Exemplo n.º 6
0
 static function set_request_locale()
 {
     // 1. Check the session specific preference (cookie)
     $locale = user::cookie_locale();
     // 2. Check the user's preference
     if (!$locale) {
         $locale = user::active()->locale;
     }
     // 3. Check the browser's / OS' preference
     if (!$locale) {
         $locale = locales::locale_from_http_request();
     }
     // If we have any preference, override the site's default locale
     if ($locale) {
         I18n::instance()->locale($locale);
     }
 }
Exemplo n.º 7
0
 /**
  * Initializes the core.
  * @return bool
  */
 public static function initialize()
 {
     if (self::$_init) {
         // Do not allow to execution twice
         return false;
     }
     self::$_init = true;
     // Determine if we are running in a Windows environment
     self::$is_win = DIRECTORY_SEPARATOR === '\\';
     // Load the logger
     self::$log = Log::instance();
     // Load the default configuration files
     self::$config = Config::instance()->attach(new Config_File());
     // Load the i18n class
     self::$i18n = I18n::instance();
     // Enable debug log
     if (self::$log_debug) {
         self::$log->attach(new Log_File(APPPATH . 'data/log/debug'), array('EXIDO_DEBUG_LOG'));
         self::$log->add('EXIDO_DEBUG_LOG', 'Initialize framework');
     }
     // Enable error log
     if (self::$log_error) {
         self::$log->attach(new Log_File(APPPATH . 'data/log/error'), array('EXIDO_ERROR_LOG'));
     }
     // Determine if we are running in a command line environment
     self::$is_cli = PHP_SAPI === 'cli';
     // Check if we have an Ajax request
     self::$is_xml = Input::instance()->isXmlRequest();
     // Load helpers
     Helper::load('lang', 'uri');
     // Check if we can use gZIP compression
     self::$use_gzip = strstr(Input::instance()->server('HTTP_ACCEPT_ENCODING'), "gzip") !== false and extension_loaded("zlib");
     // Start output buffering
     ob_start(array(__CLASS__, 'outputBuffer'));
     // Save buffering level
     self::$_buffer_level = ob_get_level();
     Event::add('system.routing', array('Router', 'getUri'));
     Event::add('system.routing', array('Router', 'initialize'));
     Event::add('system.execute', array(__CLASS__, 'instance'));
     Event::add('system.shutdown', array(__CLASS__, 'shutdown'));
     return true;
 }
Exemplo n.º 8
0
/**
 * Translates a localizable message with plural forms.
 * @param $singular String The message to be translated. E.g. "There is one album."
 * @param $plural String The plural message to be translated. E.g.
 *        "There are %count albums."
 * @param $count Number The number which is inserted for the %count placeholder and
 *        which is used to select the proper plural form ($singular or $plural).
 * @param $options array (optional) Options array for key value pairs which are used
 *        for pluralization and interpolation. Special key: "locale" to override the
 *        currently configured locale.
 * @return String The translated message string.
 */
function t2($singular, $plural, $count, $options = array())
{
    return I18n::instance()->translate(array("one" => $singular, "other" => $plural), array_merge($options, array("count" => $count)));
}
Exemplo n.º 9
0
 public static function l10n_form()
 {
     if (Input::instance()->get("show_all_l10n_messages")) {
         $calls = array();
         foreach (Database::instance()->select("key", "message")->from("incoming_translations")->where(array("locale" => 'root'))->get()->as_array() as $row) {
             $calls[$row->key] = array(unserialize($row->message), array());
         }
     } else {
         $calls = I18n::instance()->call_log();
     }
     $locale = I18n::instance()->locale();
     if ($calls) {
         $translations = array();
         foreach (Database::instance()->select("key", "translation")->from("incoming_translations")->where(array("locale" => $locale))->get()->as_array() as $row) {
             $translations[$row->key] = unserialize($row->translation);
         }
         // Override incoming with outgoing...
         foreach (Database::instance()->select("key", "translation")->from("outgoing_translations")->where(array("locale" => $locale))->get()->as_array() as $row) {
             $translations[$row->key] = unserialize($row->translation);
         }
         $string_list = array();
         $cache = array();
         foreach ($calls as $key => $call) {
             list($message, $options) = $call;
             // Ensure that the message is in the DB
             l10n_scanner::process_message($message, $cache);
             // Note: Not interpolating placeholders for the actual translation input field.
             // TODO: Might show a preview w/ interpolations (using $options)
             $translation = isset($translations[$key]) ? $translations[$key] : '';
             $string_list[] = array('source' => $message, 'key' => $key, 'translation' => $translation);
         }
         $v = new View('l10n_client.html');
         $v->string_list = $string_list;
         $v->l10n_search_form = self::_l10n_client_search_form();
         $v->plural_forms = l10n_client::plural_forms($locale);
         return $v;
     }
     return '';
 }
Exemplo n.º 10
0
 static function is_rtl($locale = null)
 {
     $locale or $locale = I18n::instance()->locale();
     list($language, $territory) = explode('_', $locale . "_");
     return in_array($language, array("he", "fa", "ar"));
 }
Exemplo n.º 11
0
 static function display_name($locale = null)
 {
     if (empty(self::$locales)) {
         self::_init_language_data();
     }
     $locale or $locale = I18n::instance()->locale();
     return self::$locales["{$locale}"];
 }
Exemplo n.º 12
0
 public static function l10n_form()
 {
     $calls = I18n::instance()->call_log();
     if ($calls) {
         $string_list = array();
         foreach ($calls as $call) {
             list($message, $options) = $call;
             // Note: Don't interpolate placeholders for the actual translation input field.
             // TODO: Use $options to generate a preview.
             if (is_array($message)) {
                 // TODO: Handle plural forms.
                 //   Translate each message. If it has a plural form, get
                 //   the current locale's plural rules and all plural translations.
                 continue;
             }
             $source = $message;
             $translation = '';
             $options_for_raw_translation = array();
             if (isset($options['count'])) {
                 $options_for_raw_translation['count'] = $options['count'];
             }
             if (I18n::instance()->has_translation($message, $options_for_raw_translation)) {
                 $translation = I18n::instance()->translate($message, $options_for_raw_translation);
             }
             $string_list[] = array('source' => $source, 'translation' => $translation);
         }
         $v = new View('l10n_client.html');
         $v->string_list = $string_list;
         $v->l10n_form = self::_l10n_client_form();
         $v->l10n_search_form = self::_l10n_client_search_form();
         return $v;
     }
     return '';
 }