本文整理汇总了PHP中Pagekit\Application::translator方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::translator方法的具体用法?PHP Application::translator怎么用?PHP Application::translator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pagekit\Application
的用法示例。
在下文中一共展示了Application::translator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
/**
* TODO: Limit catalogue if maintenance mode is enabled?
* @Route("/{locale}", requirements={"locale"="[a-zA-Z0-9_-]+"}, defaults={"_maintenance" = true})
* @Request({"locale"})
*/
public function indexAction($locale = null)
{
$intl = App::module('system/intl');
$intl->loadLocale($locale);
$messages = $intl->getFormats($locale) ?: [];
$messages['locale'] = $locale;
$messages['translations'] = [$locale => App::translator()->getCatalogue($locale)->all()];
$messages = json_encode($messages);
$request = App::request();
$json = $request->isXmlHttpRequest();
$response = $json ? App::response()->json() : App::response('', 200, ['Content-Type' => 'application/javascript']);
$response->setETag(md5($json . $messages))->setPublic();
if ($response->isNotModified($request)) {
return $response;
}
return $response->setContent($json ? $messages : sprintf('var $locale = %s;', $messages));
}
示例2: loadLocale
/**
* Loads language files.
*
* @param string $locale
* @param TranslatorInterface $translator
*/
public function loadLocale($locale, TranslatorInterface $translator = null)
{
$translator = $translator ?: App::translator();
foreach (App::module() as $module) {
$domains = [];
$path = $module->get('path') . ($module->get('languages') ?: '/languages');
$files = glob("{$path}/{$locale}/*.php") ?: [];
foreach ($files as $file) {
$format = substr(strrchr($file, '.'), 1);
$domain = basename($file, '.' . $format);
if (in_array($domain, $domains)) {
continue;
}
$domains[] = $domain;
$translator->addResource($format, $file, $locale, $domain);
}
}
}
示例3:
/**
* Translates the given choice message by choosing a translation according to a number, alias for method transChoice()
*/
function _c($id, $number, array $parameters = [], $domain = null, $locale = null)
{
return App::translator()->transChoice($id, $number, $parameters, $domain, $locale);
}