本文整理汇总了PHP中Gettext\Translations::getLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP Translations::getLanguage方法的具体用法?PHP Translations::getLanguage怎么用?PHP Translations::getLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gettext\Translations
的用法示例。
在下文中一共展示了Translations::getLanguage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toString
/**
* {@inheritdoc}
*/
public static function toString(Translations $translations, array $options = [])
{
$dom = new DOMDocument('1.0', 'utf-8');
$dom->formatOutput = true;
$xliff = $dom->appendChild($dom->createElement('xliff'));
$xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:2.0');
$xliff->setAttribute('version', '2.0');
$xliff->setAttribute('srcLang', $translations->getLanguage());
$xliff->setAttribute('trgLang', $translations->getLanguage());
$file = $xliff->appendChild($dom->createElement('file'));
$file->setAttribute('id', $translations->getDomain() . '.' . $translations->getLanguage());
//Save headers as notes
$notes = $dom->createElement('notes');
foreach ($translations->getHeaders() as $name => $value) {
$notes->appendChild(self::createTextNode($dom, 'note', $value))->setAttribute('id', $name);
}
if ($notes->hasChildNodes()) {
$file->appendChild($notes);
}
foreach ($translations as $translation) {
$unit = $dom->createElement('unit');
$unit->setAttribute('id', md5($translation->getContext() . $translation->getOriginal()));
//Save comments as notes
$notes = $dom->createElement('notes');
$notes->appendChild(self::createTextNode($dom, 'note', $translation->getContext()))->setAttribute('category', 'context');
foreach ($translation->getComments() as $comment) {
$notes->appendChild(self::createTextNode($dom, 'note', $comment))->setAttribute('category', 'comment');
}
foreach ($translation->getExtractedComments() as $comment) {
$notes->appendChild(self::createTextNode($dom, 'note', $comment))->setAttribute('category', 'extracted-comment');
}
foreach ($translation->getFlags() as $flag) {
$notes->appendChild(self::createTextNode($dom, 'note', $flag))->setAttribute('category', 'flag');
}
foreach ($translation->getReferences() as $reference) {
$notes->appendChild(self::createTextNode($dom, 'note', $reference[0] . ':' . $reference[1]))->setAttribute('category', 'reference');
}
$unit->appendChild($notes);
$segment = $unit->appendChild($dom->createElement('segment'));
$segment->appendChild(self::createTextNode($dom, 'source', $translation->getOriginal()));
$segment->appendChild(self::createTextNode($dom, 'target', $translation->getTranslation()));
foreach ($translation->getPluralTranslations() as $plural) {
if ($plural !== '') {
$segment->appendChild(self::createTextNode($dom, 'target', $plural));
}
}
$file->appendChild($unit);
}
return $dom->saveXML();
}
示例2: 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;
}
示例3: 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]);
}
}
}
示例4: 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']);
}