本文整理汇总了PHP中Gettext\Translations::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Translations::getHeader方法的具体用法?PHP Translations::getHeader怎么用?PHP Translations::getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gettext\Translations
的用法示例。
在下文中一共展示了Translations::getHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toArray
/**
* Generates an array with the translations.
*
* @param Translations $translations
*
* @return array
*/
public static function toArray(Translations $translations)
{
$array = array();
$context_glue = "";
foreach ($translations as $translation) {
$key = ($translation->hasContext() ? $translation->getContext() . $context_glue : '') . $translation->getOriginal();
$entry = array($translation->getPlural(), $translation->getTranslation());
if ($translation->hasPluralTranslation()) {
$entry = array_merge($entry, $translation->getPluralTranslation());
}
$array[$key] = $entry;
}
$domain = $translations->getDomain() ?: 'messages';
$lang = $translations->getLanguage() ?: 'en';
$fullArray = array($domain => array('' => array('domain' => $domain, 'lang' => $lang, 'plural-forms' => 'nplurals=2; plural=(n != 1);')));
if ($translations->getHeader('Plural-Forms') !== null) {
$fullArray[$domain]['']['plural-forms'] = $translations->getHeader('Plural-Forms');
}
$fullArray[$domain] = array_merge($fullArray[$domain], $array);
return $fullArray;
}
示例2: extractHeaders
/**
* Add the headers found to the translations instance.
*
* @param string $headers
* @param Translations $translations
*
* @return array
*/
private static function extractHeaders($headers, Translations $translations)
{
$headers = explode("\n", $headers);
$currentHeader = null;
foreach ($headers as $line) {
$line = self::convertString($line);
if ($line === '') {
continue;
}
if (self::isHeaderDefinition($line)) {
$header = array_map('trim', explode(':', $line, 2));
$currentHeader = $header[0];
$translations->setHeader($currentHeader, $header[1]);
} else {
$entry = $translations->getHeader($currentHeader);
$translations->setHeader($currentHeader, $entry . $line);
}
}
}
示例3: toString
/**
* {@parentDoc}.
*/
public static function toString(Translations $translations, array $options = [])
{
$domain = $translations->getDomain() ?: 'messages';
$options += static::$options;
return json_encode([$domain => ['' => ['domain' => $domain, 'lang' => $translations->getLanguage() ?: 'en', 'plural-forms' => $translations->getHeader('Plural-Forms') ?: 'nplurals=2; plural=(n != 1);']] + self::buildMessages($translations)], $options['json']);
}