本文整理汇总了PHP中Gettext\Translations::getPluralForms方法的典型用法代码示例。如果您正苦于以下问题:PHP Translations::getPluralForms方法的具体用法?PHP Translations::getPluralForms怎么用?PHP Translations::getPluralForms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gettext\Translations
的用法示例。
在下文中一共展示了Translations::getPluralForms方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toArray
/**
* Returns a multidimensional array.
*
* @param Translations $translations
* @param bool $includeHeaders
* @param bool $forceArray
*
* @return array
*/
private static function toArray(Translations $translations, $includeHeaders, $forceArray = false)
{
$pluralForm = $translations->getPluralForms();
$pluralSize = is_array($pluralForm) ? $pluralForm[0] - 1 : null;
$messages = [];
if ($includeHeaders) {
$messages[''] = ['' => [self::generateHeaders($translations)]];
}
foreach ($translations as $translation) {
$context = $translation->getContext();
$original = $translation->getOriginal();
if (!isset($messages[$context])) {
$messages[$context] = [];
}
if ($translation->hasPluralTranslations(true)) {
$messages[$context][$original] = $translation->getPluralTranslations($pluralSize);
array_unshift($messages[$context][$original], $translation->getTranslation());
} elseif ($forceArray) {
$messages[$context][$original] = [$translation->getTranslation()];
} else {
$messages[$context][$original] = $translation->getTranslation();
}
}
return ['domain' => $translations->getDomain(), 'plural-forms' => $translations->getHeader('Plural-Forms'), 'messages' => $messages];
}
示例2: toString
/**
* {@parentDoc}.
*/
public static function toString(Translations $translations, array $options = [])
{
$pluralForm = $translations->getPluralForms();
$pluralSize = is_array($pluralForm) ? $pluralForm[0] - 1 : null;
$lines = ['msgid ""', 'msgstr ""'];
foreach ($translations->getHeaders() as $name => $value) {
$lines[] = sprintf('"%s: %s\\n"', $name, $value);
}
$lines[] = '';
//Translations
foreach ($translations as $translation) {
if ($translation->hasComments()) {
foreach ($translation->getComments() as $comment) {
$lines[] = '# ' . $comment;
}
}
if ($translation->hasExtractedComments()) {
foreach ($translation->getExtractedComments() as $comment) {
$lines[] = '#. ' . $comment;
}
}
if ($translation->hasReferences()) {
foreach ($translation->getReferences() as $reference) {
$lines[] = '#: ' . $reference[0] . (!is_null($reference[1]) ? ':' . $reference[1] : null);
}
}
if ($translation->hasFlags()) {
$lines[] = '#, ' . implode(',', $translation->getFlags());
}
if ($translation->hasContext()) {
$lines[] = 'msgctxt ' . self::convertString($translation->getContext());
}
self::addLines($lines, 'msgid', $translation->getOriginal());
if ($translation->hasPlural()) {
self::addLines($lines, 'msgid_plural', $translation->getPlural());
self::addLines($lines, 'msgstr[0]', $translation->getTranslation());
foreach ($translation->getPluralTranslations($pluralSize) as $k => $v) {
self::addLines($lines, 'msgstr[' . ($k + 1) . ']', $v);
}
} else {
self::addLines($lines, 'msgstr', $translation->getTranslation());
}
$lines[] = '';
}
return implode("\n", $lines);
}
示例3: buildMessages
/**
* Generates an array with all translations.
*
* @param Translations $translations
*
* @return array
*/
private static function buildMessages(Translations $translations)
{
$pluralForm = $translations->getPluralForms();
$pluralSize = is_array($pluralForm) ? $pluralForm[0] - 1 : null;
$messages = [];
$context_glue = '\\u0004';
foreach ($translations as $translation) {
$key = ($translation->hasContext() ? $translation->getContext() . $context_glue : '') . $translation->getOriginal();
if ($translation->hasPluralTranslations(true)) {
$message = $translation->getPluralTranslations($pluralSize);
array_unshift($message, $translation->getTranslation());
} else {
$message = [$translation->getTranslation()];
}
$messages[$key] = $message;
}
return $messages;
}
示例4: mergeWith
/**
* Merges this translations with other translations.
*
* @param Translations $translations The translations instance to merge with
* @param int|null $method One or various Translations::MERGE_* constants to define how to merge the translations
*/
public function mergeWith(Translations $translations, $method = null)
{
if ($method === null) {
$method = self::$mergeDefault;
}
if ($method & self::MERGE_HEADERS) {
foreach ($translations->getHeaders() as $name => $value) {
if (!$this->getHeader($name)) {
$this->setHeader($name, $value);
}
}
}
$add = (bool) ($method & self::MERGE_ADD);
foreach ($translations as $entry) {
if ($existing = $this->find($entry)) {
$existing->mergeWith($entry, $method);
} elseif ($add) {
$this[] = clone $entry;
}
}
if ($method & self::MERGE_REMOVE) {
$filtered = array();
foreach ($this as $entry) {
if ($translations->find($entry)) {
$filtered[] = $entry;
}
}
$this->exchangeArray($filtered);
}
if ($method & self::MERGE_LANGUAGE) {
$language = $translations->getLanguage();
$pluralForm = $translations->getPluralForms();
if (!$pluralForm) {
if (!empty($language)) {
$this->setLanguage($language);
}
} else {
if (!empty($language)) {
$this->setHeader(self::HEADER_LANGUAGE, $language);
}
$this->setPluralForms($pluralForm[0], $pluralForm[1]);
}
}
}