Ejemplo n.º 1
0
function format_language($language_iso, $culture = null)
{
    $c = sfCultureInfo::getInstance($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
    $languages = $c->getLanguages();
    if (!isset($languages[$language_iso])) {
        $c = new sfCultureInfo(sfConfig::get('sf_default_culture'));
        $languages = $c->getLanguages();
    }
    return isset($languages[$language_iso]) ? $languages[$language_iso] : $language_iso;
}
Ejemplo n.º 2
0
/**
 * Returns a <selectize> tag populated with all the languages in the world (or almost).
 *
 * The select_language_tag builds off the traditional select_tag function, and is conveniently populated with
 * all the languages in the world (sorted alphabetically). Each option in the list has a two or three character
 * language/culture code for its value and the language's name as its display title.  The country data is
 * retrieved via the sfCultureInfo class, which stores a wide variety of i18n and i10n settings for various
 * countries and cultures throughout the world. Here's an example of an <option> tag generated by the select_country_tag:
 *
 * <samp>
 *  <option value="en">English</option>
 * </samp>
 *
 * <b>Examples:</b>
 * <code>
 *  echo select_language_tag('language', 'de');
 * </code>
 *
 * @param  string $name     field name
 * @param  string $selected selected field values (two or three-character language/culture code)
 * @param  array  $options  additional HTML compliant <select> tag parameters
 *
 * @return string <selectize> tag populated with all the languages in the world.
 * @see select_tag, options_for_select, sfCultureInfo
 */
function object_multiselect_language_tag($name, $selected = null, $options = array())
{
    $c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
    $languages = $c->getLanguages();
    if ($language_option = _get_option($options, 'languages')) {
        foreach ($languages as $key => $value) {
            if (!in_array($key, $language_option)) {
                unset($languages[$key]);
            }
        }
    }
    asort($languages);
    $option_tags = options_for_select($languages, $selected, $options);
    unset($options['include_blank'], $options['include_custom']);
    return select_tag($name, $option_tags, $options);
}
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * culture:   The culture to use for internationalized strings (required)
  *  * languages: An array of language codes to use (ISO 639-1)
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetFormSelect
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addRequiredOption('culture');
     $this->addOption('languages');
     // populate choices with all languages
     $culture = isset($options['culture']) ? $options['culture'] : 'en';
     $cultureInfo = new sfCultureInfo($culture);
     $languages = $cultureInfo->getLanguages();
     // restrict languages to a sub-set
     if (isset($options['languages'])) {
         if ($problems = array_diff($options['languages'], array_keys($languages))) {
             throw new InvalidArgumentException(sprintf('The following languages do not exist: %s.', implode(', ', $problems)));
         }
         $languages = array_intersect_key($languages, array_flip($options['languages']));
     }
     asort($languages);
     $this->setOption('choices', $languages);
 }
Ejemplo n.º 4
0
function format_language($language_iso, $culture = null)
{
    $c = new sfCultureInfo($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
    $languages = $c->getLanguages();
    return isset($languages[$language_iso]) ? $languages[$language_iso] : '';
}
Ejemplo n.º 5
0
 private function getDefaultLanguage($textual = false)
 {
     $language = 'en';
     if (!$this->vocabulary) {
         $this->vocabulary = VocabularyPeer::retrieveByPk($this->getRequestParameter('id'));
     }
     if (isset($this->vocabulary)) {
         $language = $this->vocabulary->getLanguage();
     }
     if (!$textual) {
         return $language;
     } else {
         $culture = 'en';
         /** @var sfUser $user */
         $user = $this->getUser();
         if ($user) {
             $culture = $user->getCulture();
         }
         $cultureInfo = new sfCultureInfo($culture);
         $languages = $cultureInfo->getLanguages();
         return $languages[$language];
     }
 }
Ejemplo n.º 6
0
$sfExtjs3Plugin->begin();
$sfExtjs3Plugin->end();
?>
<script type='text/javascript'>

Ext.namespace('Login');
  Login = function(){
    var loginWindow, loginForm;    
    return{
      init:function(){
        Ext.QuickTips.init();
        Ext.form.Field.prototype.msgTarget = 'side';
          
        <?php 
$culture = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
$languages = $culture->getLanguages(array('pt', 'en'));
$js_languages = array();
foreach ($languages as $language_code => $language_name) {
    $js_languages[] = "[" . json_encode($language_code) . ', ' . json_encode(ucfirst($language_name)) . "]";
}
$language_js = implode(',', $js_languages);
echo "var language_data = [" . $language_js . "];";
?>

        //language_data
        /* Language chooser combobox  */
        var store = new Ext.data.ArrayStore({
            fields: ['code', 'language'],
            data : language_data});

        var combo = new Ext.form.ComboBox({
// __toString()
$t->diag('__toString()');
$c = new sfCultureInfo();
$t->is($c->__toString(), 'en', '->__toString() returns the name of the culture');
try {
    $c = new sfCultureInfo('xxx');
    $t->fail('->__construct() throws an exception if the culture is not valid');
} catch (sfException $e) {
    $t->pass('->__construct() throws an exception if the culture is not valid');
}
$c_en = new sfCultureInfo();
$c_fr = new sfCultureInfo('fr');
// ->getLanguages()
$t->diag('->getLanguages()');
$languages_en = $c_en->getLanguages();
$languages_fr = $c_fr->getLanguages();
$t->is($languages_en['fr'], 'French', '->getLanguages() returns a list of languages in the language of the localized version');
$t->is($languages_fr['fr'], 'français', '->getLanguages() returns a list of languages in the language of the localized version');
$t->is($languages_en, $c_en->Languages, '->getLanguages() is equivalent to ->Languages');
// ->getCurrencies()
$t->diag('->getCurrencies()');
$currencies_en = $c_en->getCurrencies();
$currencies_fr = $c_fr->getCurrencies();
$t->is($currencies_en['EUR'][1], 'Euro', '->getCurrencies() returns a list of currencies in the language of the localized version');
$t->is($currencies_fr['EUR'][1], 'euro', '->getCurrencies() returns a list of currencies in the language of the localized version');
$t->is($currencies_en, $c_en->Currencies, '->getCurrencies() is equivalent to ->Currencies');
// ->getCountries()
$t->diag('->getCountries()');
$countries_en = $c_en->getCountries();
$countries_fr = $c_fr->getCountries();
$t->is($countries_en['ES'], 'Spain', '->getCountries() returns a list of countries in the language of the localized version');