public static function assign($c, $language, $country, $numPlurals = null, $pluralRule = '', $pluralCases = array()) { $country = (string) $country; $data = array('cID' => $c->getCollectionID(), 'msLanguage' => $language, 'msCountry' => $country); $pluralRule = (string) $pluralRule; if (empty($numPlurals) || $pluralRule === '' || empty($pluralCases)) { $locale = $language; if ($country !== '') { $locale .= '_' . $country; } $localeInfo = \Gettext\Languages\Language::getById($locale); if ($localeInfo) { $numPlurals = count($localeInfo->categories); $pluralRule = $localeInfo->formula; $pluralCases = array(); foreach ($localeInfo->categories as $category) { $pluralCases[] = $category->id . '@' . $category->examples; } } } if (!empty($numPlurals) && $pluralRule !== '' && !empty($pluralCases)) { $data['msNumPlurals'] = $numPlurals; $data['msPluralRule'] = $pluralRule; $data['msPluralCases'] = is_array($pluralCases) ? implode("\n", $pluralCases) : $pluralCases; } $db = Database::get(); $db->Replace('MultilingualSections', $data, array('cID'), true); // Now we make sure we have multilingual enabled Config::save('concrete.multilingual.enabled', true); }
public function updatePluralSettings(Locale $l, $numPlurals = null, $pluralRule = '', $pluralCases = []) { if (empty($numPlurals) || $pluralRule === '' || empty($pluralCases)) { $locale = $l->getLocale(); $localeInfo = \Gettext\Languages\Language::getById($locale); if ($localeInfo) { $numPlurals = count($localeInfo->categories); $pluralRule = $localeInfo->formula; $pluralCases = []; foreach ($localeInfo->categories as $category) { $pluralCases[] = $category->id . '@' . $category->examples; } $pluralCases = is_array($pluralCases) ? implode("\n", $pluralCases) : $pluralCases; $l->setNumPlurals($numPlurals); $l->setPluralCases($pluralCases); $l->setPluralRule($pluralRule); } } if (!empty($numPlurals) && $pluralRule !== '' && !empty($pluralCases)) { $l->setPluralRule($pluralRule); $l->setNumPlurals($numPlurals); $pluralCases = is_array($pluralCases) ? implode("\n", $pluralCases) : $pluralCases; $l->setPluralCases($pluralCases); } return $l; }
public function postUp(Schema $schema) { $db = \Database::get(); if ($this->updateSectionPlurals) { $rs = $db->Execute('select cID, msLanguage, msCountry from MultilingualSections'); while ($row = $rs->FetchRow()) { $locale = $row['msLanguage']; if ($row['msCountry']) { $locale .= '_' . $row['msCountry']; } $localeInfo = \Gettext\Languages\Language::getById($locale); if ($localeInfo) { $pluralCases = array(); foreach ($localeInfo->categories as $category) { $pluralCases[] = $category->id . '@' . $category->examples; } $db->update('MultilingualSections', array('msNumPlurals' => count($localeInfo->categories), 'msPluralRule' => $localeInfo->formula, 'msPluralCases' => implode("\n", $pluralCases)), array('cID' => $row['cID'])); } } } if ($this->updateMultilingualTranslations) { $db->Execute("UPDATE MultilingualTranslations SET comments = REPLACE(comments, ':', '\\n') WHERE comments IS NOT NULL"); } }
/** * Sets the language and the plural forms. * * @param string $language * * @return bool Returns true if the plural rules has been updated, false if $language hasn't been recognized */ public function setLanguage($language) { $this->setHeader(self::HEADER_LANGUAGE, trim($language)); if ($info = Language::getById($language)) { $this->setPluralForms(count($info->categories), $info->formula); return true; } return false; }
/** * Sets the language and the plural forms. * * @param string $language * * @throws InvalidArgumentException if the language hasn't been recognized * * @return self */ public function setLanguage($language) { $this->setHeader(self::HEADER_LANGUAGE, trim($language)); if ($info = Language::getById($language)) { return $this->setPluralForms(count($info->categories), $info->formula); } throw new InvalidArgumentException(sprintf('The language "%s" is not valid', $language)); }
}); require_once dirname(__DIR__) . '/src/autoloader.php'; // Parse the command line options Enviro::initialize(); try { if (isset(Enviro::$languages)) { $languages = array(); foreach (Enviro::$languages as $languageId) { $language = Language::getById($languageId); if (!isset($language)) { throw new Exception("Unable to find the language with id '{$languageId}'"); } $languages[] = $language; } } else { $languages = Language::getAll(); } if (Enviro::$reduce) { $languages = Enviro::reduce($languages); } if (isset(Enviro::$outputFilename)) { echo call_user_func(array(Exporter::getExporterClassName(Enviro::$outputFormat), 'toFile'), $languages, Enviro::$outputFilename, array('us-ascii' => Enviro::$outputUSAscii)); } else { echo call_user_func(array(Exporter::getExporterClassName(Enviro::$outputFormat), 'toString'), $languages, array('us-ascii' => Enviro::$outputUSAscii)); } } catch (Exception $x) { Enviro::echoErr($x->getMessage() . "\n"); Enviro::echoErr("Trace:\n"); Enviro::echoErr($x->getTraceAsString() . "\n"); die(4); }