本文整理汇总了PHP中Phalcon\DiInterface::getLang方法的典型用法代码示例。如果您正苦于以下问题:PHP DiInterface::getLang方法的具体用法?PHP DiInterface::getLang怎么用?PHP DiInterface::getLang使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\DiInterface
的用法示例。
在下文中一共展示了DiInterface::getLang方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateMultilingualRoutes
protected function generateMultilingualRoutes(DiInterface $di = null)
{
$langService = $di->getLang();
$keys = [];
$routesWithKeys = [];
//find keys of routes
foreach ($this->multilingualRoutes as $route) {
$tempKeys = [];
preg_match_all('/<([a-z0-9-]*)>/', $route['pattern'], $tempKeys);
$keys = array_merge($keys, $tempKeys[1]);
$routesWithKeys[] = ['route' => $route, 'key' => $tempKeys[1]];
}
//translate keys for all routes
$translations = $langService->getTranslations($keys);
foreach ($routesWithKeys as $route) {
$keys = $route['key'];
foreach ($langService->getAvailableLangs() as $lang) {
//find translation of pattern parts for lang
$translationsForRoute = [];
$key = "";
foreach ($keys as $key) {
if (isset($translations[$lang][$key])) {
$translationsForRoute['<' . $key . '>'] = $translations[$lang][$key];
} else {
$translationsForRoute['<' . $key . '>'] = $key;
}
}
if (isset($route['route']['name']) && $route['route']['name'] !== null) {
$key = $route['route']['name'];
}
//translate parts of pattern
$pattern = strtr($route['route']['pattern'], $translationsForRoute);
//add route
$this->add('/' . $lang . '/' . $pattern, $route['route']['paths'])->setName($key . "|" . $lang);
$this->translatedRoutes = $translations;
}
}
}