本文整理汇总了PHP中Symfony\Component\Translation\TranslatorInterface::addResource方法的典型用法代码示例。如果您正苦于以下问题:PHP TranslatorInterface::addResource方法的具体用法?PHP TranslatorInterface::addResource怎么用?PHP TranslatorInterface::addResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Translation\TranslatorInterface
的用法示例。
在下文中一共展示了TranslatorInterface::addResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* @see Behat\Behat\Context\Loader\ContextLoaderInterface::load()
*/
public function load(ContextInterface $context)
{
foreach ($context->getTranslationResources() as $path) {
$extension = pathinfo($path, PATHINFO_EXTENSION);
if ('yml' === $extension) {
$this->translator->addResource('yaml', $path, basename($path, '.yml'), 'behat.definitions');
} elseif ('xliff' === $extension) {
$this->translator->addResource('xliff', $path, basename($path, '.xliff'), 'behat.definitions');
} elseif ('php' === $extension) {
$this->translator->addResource('php', $path, basename($path, '.php'), 'behat.definitions');
} else {
throw new \InvalidArgumentException(sprintf('Can not read definitions translations from file "%s". File is not supported', $path));
}
}
}
示例2: addResourceDir
/**
* @param string $dir
*/
public static function addResourceDir($dir)
{
if (in_array($dir, static::$dirs)) {
return;
}
$iterator = new \FilesystemIterator($dir, \FilesystemIterator::SKIP_DOTS);
foreach ($iterator as $value) {
if (!$iterator->isFile()) {
continue;
}
list($domain, $locale, $format) = explode('.', $iterator->getBasename(), 3);
static::$translator->addResource($format, $iterator->getRealPath(), $locale, $domain);
}
static::$dirs[] = $dir;
}