本文整理匯總了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']);
}