本文整理汇总了PHP中Gettext\Translations::setDomain方法的典型用法代码示例。如果您正苦于以下问题:PHP Translations::setDomain方法的具体用法?PHP Translations::setDomain怎么用?PHP Translations::setDomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gettext\Translations
的用法示例。
在下文中一共展示了Translations::setDomain方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAllKnownTranslationFunctionsAreCovered
/**
* All known translation functions are covered.
*/
public function testAllKnownTranslationFunctionsAreCovered()
{
$extractor = new WordPressExtractor();
$translations = new Translations();
$translations->setDomain('test');
$translations = $extractor->fromDirectory($this->getResourcesPath() . 'commonSources', $translations);
// file_put_contents($this->getResourcesPath() . 'commonSources.php', var_export($arrayCopy, true));
$poContent = $translations->toPoString();
// strip base path for better comparison
$poContent = str_replace($this->getResourcesPath(), '', $poContent);
$this->assertContains('"translate"', $poContent);
$this->assertContains('"translate_with_gettext_context"', $poContent);
$this->assertContains('"__"', $poContent);
$this->assertContains('"_x"', $poContent);
$this->assertContains('"_e"', $poContent);
$this->assertContains('"_ex"', $poContent);
$this->assertContains('"esc_attr__"', $poContent);
$this->assertContains('"esc_attr_e"', $poContent);
$this->assertContains('"esc_attr_x"', $poContent);
$this->assertContains('"esc_html__"', $poContent);
$this->assertContains('"esc_html_e"', $poContent);
$this->assertContains('"esc_html_x"', $poContent);
$this->assertContains('"_n-single"', $poContent);
$this->assertContains('"_n-plural"', $poContent);
$this->assertContains('"_nx-context"', $poContent);
$this->assertContains('"_nx-single"', $poContent);
$this->assertContains('"_nx-plural"', $poContent);
$this->assertContains('"_n_noop-singular"', $poContent);
$this->assertContains('"_n_noop-plural"', $poContent);
$this->assertContains('"_nx_noop-context"', $poContent);
$this->assertContains('"_nx_noop-singular"', $poContent);
$this->assertContains('"_nx_noop-plural"', $poContent);
}
示例2: handleArray
/**
* Handle an array of translations and append to the Translations instance.
*
* @param array $content
* @param Translations $translations
*/
public static function handleArray(array $content, Translations $translations)
{
$content = current($content);
$translations_info = isset($content['']) ? $content[''] : null;
unset($content['']);
if (isset($translations_info['domain'])) {
$translations->setDomain($translations_info['domain']);
}
foreach ($content as $key => $message) {
static::insertTranslation($translations, $key, $message);
}
}
示例3: handleArray
/**
* Handle an array of translations and append to the Translations instance
*
* @param array $content
* @param Translations $translations
*/
public static function handleArray(array $content, Translations $translations)
{
$content = $content['messages'];
$translations_info = isset($content['']) ? $content[''] : null;
unset($content['']);
if (isset($translations_info['domain'])) {
$translations->setDomain($translations_info['domain']);
}
$context_glue = '\\u0004';
foreach ($content as $key => $message) {
$key = explode($context_glue, $key);
$context = isset($key[1]) ? array_shift($key) : '';
$original = array_shift($key);
$plural = array_shift($message);
$translation = array_shift($message);
$plural_translation = array_shift($message);
$entry = $translations->insert($context, $original, $plural);
$entry->setTranslation($translation);
$entry->setPluralTranslation($plural_translation);
}
}
示例4: extract
/**
* Handle an array of translations and append to the Translations instance.
*
* @param array $content
* @param Translations $translations
*/
public static function extract(array $content, Translations $translations)
{
$messages = current($content);
$headers = isset($messages['']) ? $messages[''] : null;
unset($messages['']);
if (!empty($headers['domain'])) {
$translations->setDomain($headers['domain']);
}
if (!empty($headers['lang'])) {
$translations->setLanguage($headers['lang']);
}
if (!empty($headers['plural-forms'])) {
$translations->setHeader(Translations::HEADER_PLURAL, $headers['plural-forms']);
}
$context_glue = '\\u0004';
foreach ($messages as $key => $translation) {
$key = explode($context_glue, $key);
$context = isset($key[1]) ? array_shift($key) : '';
$translations->insert($context, array_shift($key))->setTranslation(array_shift($translation))->setPluralTranslations($translation);
}
}
示例5: fromArray
/**
* Extract the entries from a multidimensional array.
*
* @param array $messages
* @param Translations $translations
*/
private static function fromArray(array $messages, Translations $translations)
{
if (!empty($messages['domain'])) {
$translations->setDomain($messages['domain']);
}
if (!empty($messages['plural-forms'])) {
$translations->setHeader(Translations::HEADER_PLURAL, $messages['plural-forms']);
}
foreach ($messages['messages'] as $context => $contextTranslations) {
foreach ($contextTranslations as $original => $value) {
if ($context === '' && $original === '') {
self::extractHeaders(is_array($value) ? array_shift($value) : $value, $translations);
continue;
}
$translation = $translations->insert($context, $original);
if (is_array($value)) {
$translation->setTranslation(array_shift($value));
$translation->setPluralTranslations($value);
} else {
$translation->setTranslation($value);
}
}
}
}