由于TYPO3版本9.5 RouteEnhancer
s可用于将扩展参数转换为美观且易于理解的URL路径。
扩展名news
的示例配置如下:
routeEnhancers:
News:
type: Extbase
extension: News
plugin: Pi1
routes:
-
routePath: '/page/{page}'
_controller: 'News::list'
_arguments:
page: '@widget_0/currentPage'
-
routePath: '/article/{news_title}'
_controller: 'News::detail'
_arguments:
news_title: news
-
routePath: '/category/{category_name}'
_controller: 'News::list'
_arguments:
category_name: overwriteDemand/categories
-
routePath: '/tag/{tag_name}'
_controller: 'News::list'
_arguments:
tag_name: overwriteDemand/tags
defaultController: 'News::list'
defaults:
page: '0'
requirements:
news_title: '^[a-zA-Z0-9].*$'
page: \d+
aspects:
news_title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
page:
type: StaticRangeMapper
start: '1'
end: '100'
category_name:
type: PersistedAliasMapper
tableName: sys_category
routeFieldName: title
tag_name:
type: PersistedAliasMapper
tableName: tx_news_domain_model_tag
routeFieldName: title
我的问题是:
如何本地化上述routePath
的静态配置路径段,以便将page
,article
,category
和tag
转换为当前语言?
答案 0 :(得分:1)
请查看文章“ https://typo3worx.eu/2018/12/typo3-routing-extensions-and-enhancers”中的“ Localemodifier”段落。 (博客是有用信息的宝库;))。
与您的问题有关的基本信息是:
LOCALEMODIFIER
LocaleModifier在两种语言之间“翻译” URL的一部分。如果url中有静态字符串(在各种语言中看起来应该有所不同),这将很有用。一个示例可以是产品数据库,例如以下示例:routeEnhancers: NewsArchive: type: Extbase limitToPages: [13] extension: MyProducts plugin: Pi1 routes: - { routePath: '/{localized_product}/{product}', _controller: 'MyProducts::detail' } defaultController: 'MyProducts::list' aspects: localized_product: type: LocaleModifier default: 'product' localeMap: - locale: 'fr_FR.*|fr_CA.*' value: 'produit' - locale: 'de_DE.*' value: 'produkt' - locale: 'es_ES.*' value: 'producto'
我不知道是否可以使用locallang.xlf文件在路由的静态部分和所使用的语言之间进行这种映射。
答案 1 :(得分:1)
可以根据我的问题添加简单的翻译,例如@Ricardo为我发现的,请在此页面上寻找他的答案。
更复杂的事情只有通过替换(至少)一个类才有可能。
替换非常容易,并且由于现有类中的方法非常有限,将来通过在内核旁边引入自己的代码来获得一些不兼容性的危险也很小。
那么,如何替换与RouteEnhancers
相关的类?
所有重要类都在全局数组$GLOBALS['TYPO3_CONF_VARS']
中引用,并且可以在文件typo3conf/LocalConfiguration.php
或typo3conf/AdditionalConfiguration.php
中进行定义。
将本地化值映射到已定义本地(例如de_DE,en_GB,en_US)所需的类是这样注册的:
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['LocaleModifier'] = \TYPO3\CMS\Core\Routing\Aspect\LocaleModifier::class;
在那里定义自己的类可以提供其他功能。
可以定义其他哪些与路由相关的类?
路由机制非常复杂,因此存在多个可以轻松替换的类。
要获得预定义和可替换类的概述,可以验证
通过打开
在TYPO3后端中的数组$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']
模块System
-> Configuration
,然后在页面顶部的下拉字段中选择$GLOBALS['TYPO3_CONF_VARS'] (Global Configuration)
。
在当前版本TYPO3-9.5.5中,配置了以下默认类
// Aspects
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['LocaleModifier'] = TYPO3\CMS\Core\Routing\Aspect\LocaleModifier::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['PersistedAliasMapper'] = TYPO3\CMS\Core\Routing\Aspect\PersistedAliasMapper::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['PersistedPatternMapper'] = TYPO3\CMS\Core\Routing\Aspect\PersistedPatternMapper::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['StaticRangeMapper'] = TYPO3\CMS\Core\Routing\Aspect\StaticRangeMapper::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['StaticValueMapper'] = TYPO3\CMS\Core\Routing\Aspect\StaticValueMapper::class;
// Enhancers
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['enhancers']['Extbase'] = TYPO3\CMS\Extbase\Routing\ExtbasePluginEnhancer::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['enhancers']['PageType'] = TYPO3\CMS\Core\Routing\Enhancer\PageTypeDecorator::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['enhancers']['Plugin'] = TYPO3\CMS\Core\Routing\Enhancer\PluginEnhancer::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['enhancers']['Simple'] = TYPO3\CMS\Core\Routing\Enhancer\SimpleEnhancer::class;
目前,我不需要自己编写解决方案,但是如果您已经编写了一个解决方案,请随时发表答案。