Ejemplo n.º 1
0
function constructRulesUsingCallBack($rules, \Languages $langs, $task)
{
    foreach ($rules as $fieldType => $rule) {
        foreach ($langs->all() as $lang) {
            $task($langRules, $fieldType, $lang, $rule);
        }
    }
    return $langRules;
}
Ejemplo n.º 2
0
 public function save(array $options = array())
 {
     if (!$this->exists()) {
         parent::save();
     }
     $langs = Languages::all();
     foreach ($langs as $lang) {
         $translation = Translations::find($this->table . "_" . $this->id . "_" . strtolower($lang->code));
         if ($lang->code == Config::get('cms.currlang.code') || !isset($translation->exists)) {
             //check if translation exists
             if (isset($translation->exists)) {
             } else {
                 $translation = new Translations();
             }
             $translation->id = $this->table . "_" . $this->id . "_" . strtolower($lang->code);
             $translation->translation = json_encode($this->getAttributes());
             $translation->save();
         }
     }
     return;
 }
 public function execute(array &$param_pool = null)
 {
     $result = new XMLElement('fl-languages');
     $main_lang = FLang::getMainLang();
     $crt_lc = FLang::getLangCode();
     $lang_names = Languages::all()->listAll();
     $langs = FLang::getLangs();
     $current_language_xml = new XMLElement('current-language', $lang_names[$crt_lc] ? $lang_names[$crt_lc]['name'] : $crt_lc);
     $current_language_xml->setAttribute('handle', $crt_lc);
     $current_language_xml->setAttribute('language', FLang::getLang());
     $current_language_xml->setAttribute('region', FLang::getReg());
     $result->appendChild($current_language_xml);
     $supported_languages_xml = new XMLElement('supported-languages');
     foreach ($langs as $lc) {
         $lang_xml = new XMLElement('item', $lang_names[$lc] ? $lang_names[$lc]['name'] : $lc);
         $lang_xml->setAttribute('handle', $lc);
         if ($lc === $main_lang) {
             $lang_xml->setAttribute('main', 'yes');
         }
         $supported_languages_xml->appendChild($lang_xml);
     }
     $result->appendChild($supported_languages_xml);
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * Get language options for in desired language. Useful to build a Select widget.
  *
  * @param array|string|int $selected - An array of language codes to mark as selected
  * @param array            $pool     (optional) - An array of language codes to be displayed. Leave null to show all.
  * @param string           $lang     (optional) - Get language names for this language.
  *
  * @return array
  */
 public static function findOptions($selected = array(), $pool = null, $lang = null)
 {
     if (!is_array($selected)) {
         $selected = array($selected);
     }
     $native = Languages::all()->listAll('name');
     if (is_array($pool)) {
         $native = array_intersect_key($native, array_flip($pool));
     }
     if ($lang === null) {
         $lang = Lang::get();
     }
     // try to get languages in author language
     $local = Languages::local()->listAll($lang);
     // if languages not found, use english ones
     if ($local === false) {
         $local = Languages::local()->listAll();
     }
     $options = array();
     foreach ($native as $code => $info) {
         $options[] = array($code, in_array($code, $selected), sprintf("[%s] %s%s", strtoupper($code), isset($local[$code]) ? $local[$code] . ' || ' : '', $info['name']));
     }
     return $options;
 }
Ejemplo n.º 5
0
 /**
  * Set language codes
  *
  * @param $langs
  *
  * @return boolean
  */
 public static function setLangs($langs)
 {
     $langs = explode(',', General::sanitize($langs));
     // if no language codes, return false
     if ($langs === false || !is_array($langs)) {
         return false;
     }
     $langs = self::cleanLanguageCodes($langs);
     if (count($langs) === 0) {
         return false;
     }
     $new_codes = array();
     $all_codes = array_keys(Languages::all()->listAll());
     // only valid language codes are preserved
     foreach ($langs as $lc) {
         if (in_array($lc, $all_codes)) {
             $new_codes[] = $lc;
         }
     }
     // if no valid language codes, return false
     if (empty($new_codes)) {
         return false;
     }
     // store the new language codes
     self::$_langs = $new_codes;
     return true;
 }