本文整理汇总了PHP中Zend\I18n\Translator\Translator::addTranslationFilePattern方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::addTranslationFilePattern方法的具体用法?PHP Translator::addTranslationFilePattern怎么用?PHP Translator::addTranslationFilePattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\I18n\Translator\Translator
的用法示例。
在下文中一共展示了Translator::addTranslationFilePattern方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
$this->app->configs->setDefaultConfig($this->id, new TranslatorConfig(), $this);
$this->translator = $translator = new Translator();
/** @var TranslatorConfig $config */
$this->moduleConfig = $config = $this->app->configs->getConfig($this->id);
if (!$this->app->getConfig()->developmentMode) {
$c = new Filesystem();
$o = new FilesystemOptions();
$o->setCacheDir($this->app->cacheStorage->createStorage($this->id));
$c->setOptions($o);
$c->addPlugin(new Serializer());
$translator->setCache($c);
}
$translator->setLocale($config->defaultLanguage);
$folder = $this->app->parseUri($config->translationsDirectory);
foreach ($config->contexts as $context => $file) {
if (is_int($context)) {
$context = $file;
$file .= '.mo';
}
$translator->addTranslationFilePattern('gettext', $folder, '%s/' . $file, $context);
}
$this->translator = $translator;
}
示例2: testTranslateNonExistantLocale
public function testTranslateNonExistantLocale()
{
$this->translator->addTranslationFilePattern('phparray', $this->testFilesDir . '/testarray', 'translation-%s.php');
// Test that a locale without translations does not cause warnings
$this->translator->setLocale('es_ES');
$this->assertEquals('Message 1', $this->translator->translate('Message 1'));
$this->assertEquals('Message 9', $this->translator->translate('Message 9'));
$this->translator->setLocale('fr_FR');
$this->assertEquals('Message 1', $this->translator->translate('Message 1'));
$this->assertEquals('Message 9', $this->translator->translate('Message 9'));
}
示例3: createService
public function createService(ServiceLocatorInterface $sm)
{
$configManager = $sm->get('Base\\Manager\\ConfigManager');
$locale = $configManager->need('i18n.locale');
$translator = new Translator();
$translator->addTranslationFilePattern('phparray', getcwd() . '/data/res/i18n/', '%s/backend.php');
$translator->addTranslationFilePattern('phparray', getcwd() . '/data/res/i18n/', '%s/base.php');
$translator->addTranslationFilePattern('phparray', getcwd() . '/data/res/i18n/', '%s/booking.php');
$translator->addTranslationFilePattern('phparray', getcwd() . '/data/res/i18n/', '%s/calendar.php');
$translator->addTranslationFilePattern('phparray', getcwd() . '/data/res/i18n/', '%s/frontend.php');
$translator->addTranslationFilePattern('phparray', getcwd() . '/data/res/i18n/', '%s/service.php');
$translator->addTranslationFilePattern('phparray', getcwd() . '/data/res/i18n/', '%s/setup.php');
$translator->addTranslationFilePattern('phparray', getcwd() . '/data/res/i18n/', '%s/square.php');
$translator->addTranslationFilePattern('phparray', getcwd() . '/data/res/i18n/', '%s/user.php');
$translator->setLocale($locale);
return new \Zend\Mvc\I18n\Translator($translator);
}
示例4: bootstrap
private function bootstrap($configuration)
{
// setup service manager
$serviceManager = new ServiceManager(new ServiceManagerConfig());
$serviceManager->setService('ApplicationConfig', $configuration);
// set translator
$translator = new Translator();
$translator->addTranslationFilePattern('gettext', CASASYNC_PLUGIN_DIR . 'vendor/casasoft/casamodules/src/CasasoftStandards/language/', '%s.mo', 'casasoft-standards');
$translator->setLocale(substr(get_bloginfo('language'), 0, 2));
$serviceManager->setService('Translator', $translator);
// mvc translator
$MVCtranslator = new \Zend\Mvc\I18n\Translator($translator);
$MVCtranslator->addTranslationFile('phpArray', CASASYNC_PLUGIN_DIR . 'resources/languages/' . substr(get_bloginfo('language'), 0, 2) . '/Zend_Validate.php', 'default');
\Zend\Validator\AbstractValidator::setDefaultTranslator($MVCtranslator);
$this->translator = $translator;
// load modules -- which will provide services, configuration, and more
$serviceManager->get('ModuleManager')->loadModules();
//renderer
$this->renderer = new PhpRenderer();
$pluginManager = $this->renderer->getHelperPluginManager();
//view helper plugins
$defaultHelperMapClasses = ['Zend\\Form\\View\\HelperConfig', 'Zend\\I18n\\View\\HelperConfig', 'Zend\\Navigation\\View\\HelperConfig'];
foreach ($defaultHelperMapClasses as $configClass) {
if (is_string($configClass) && class_exists($configClass)) {
$config = new $configClass();
$config->configureServiceManager($pluginManager);
}
}
$this->serviceManager = $serviceManager;
$this->queryService = $this->serviceManager->get('casawpQuery');
$this->categoryService = $this->serviceManager->get('CasasoftCategory');
$this->numvalService = $this->serviceManager->get('CasasoftNumval');
}
示例5: Translator
#!/usr/bin/env php
<?php
/**
* ZF2rapid - Zend Framework 2 Rapid Development Tool
*
* @link https://github.com/ZFrapid/zf2rapid
* @copyright Copyright (c) 2014 - 2015 Ralf Eggert
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
*/
use Zend\I18n\Translator\Translator;
use ZF2rapid\Console\Application;
use ZF2rapid\Console\Console;
// define application root
define('ZF2RAPID_ROOT', __DIR__ . '/..');
// get vendor autoloading
include ZF2RAPID_ROOT . '/vendor/autoload.php';
// set locale
Locale::setDefault('en_US');
// setup translator
$translator = new Translator();
$translator->addTranslationFilePattern('PhpArray', ZF2RAPID_ROOT . '/language', '%s.php', 'default');
// setup console
$console = new Console();
$console->setTranslator($translator);
// configure applications
$application = new Application(include ZF2RAPID_ROOT . '/config/routes.php', $console, $translator);
// run application
$exit = $application->run();
exit($exit);
示例6: translate
static function translate($lang = null)
{
$lang = '';
try {
$config = Utility::getConfig();
$lang = isset($config['lang']) ? $config['lang'] : '';
} catch (\Exception $e) {
}
if ($lang == '') {
$lang = 'en_us';
}
$type = 'Gettext';
$pattern = $lang . '.mo';
$base_dir = __DIR__ . '/../../../../../language/';
$translator = new Translator();
$translator->setLocale("en");
$translator->addTranslationFilePattern($type, $base_dir, $pattern);
return $translator;
}
示例7: addTranslationsUsingPattern
/**
* Adds a series of translation files given a pattern.
*
* This method will search the base directory for a series of files mathing the given pattern (where %s is replaces
* by the two-letter locale shorthand) and adds any translations to the translation table.
*
* @param string $baseDir Directory to search in (not-recursive)
* @param string $textDomain The domain to assign the translation messages to.
* @param string $pattern The pattern used to load files for all languages, one variable `%s` is supported and
* is replaced with the {@link http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ISO-639-1 code} for each
* locale that is requested by the translate method.
*
* @internal this method is not to be used by consumers; it is an extension of the Zend Translator component
* and is overridden to clear the messages caching array so it may be rebuild.
*
* @see self::addTranslationFolder() to provide a series of translation files.
*
* @return $this|ZendTranslator
*/
public function addTranslationsUsingPattern($baseDir, $textDomain = self::DEFAULT_DOMAIN, $pattern = self::DEFAULT_PATTERN)
{
if ($textDomain !== self::DEFAULT_DOMAIN && $pattern === self::DEFAULT_PATTERN) {
$pattern = $textDomain . '.' . $pattern;
}
parent::addTranslationFilePattern(self::TRANSLATION_FILE_TYPE, $baseDir, $pattern, $textDomain);
$this->messages = array();
return $this;
}