示例#1
0
 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;
 }