本文整理匯總了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);
}