Routes 在Type3 RouteHander中定位routePath的静态段

Routes 在Type3 RouteHander中定位routePath的静态段,routes,localization,typo3,url-routing,typo3-9.x,Routes,Localization,Typo3,Url Routing,Typo3 9.x,由于TYPO3版本9.5RouteEnhancers可用于将扩展的参数转换为良好且人类可读的URL路径 扩展名news的示例配置如下: routeEnhancers: News: type: Extbase extension: News plugin: Pi1 routes: - routePath: '/page/{page}' _controller: 'News::list' _argumen

由于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
s的静态配置路径段本地化,以便将
page
article
category
tag
翻译为当前语言?

请查看文章中的“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文件在路线的静态部分和使用的语言之间进行这种映射。

根据我的问题可以添加简单的翻译,如@Ricardo为我发现的,在这页上查找他的答案

更复杂的事情只能通过替换(至少)一个类来实现

替换非常容易,而且由于现有类中的方法非常有限,将来通过在核心旁边引入自己的代码来获得一些不兼容的危险也非常小

那么,如何替换与
RouteEnhancers
相关的类呢?

所有重要的类都在全局数组
$GLOBALS['TYPO3_CONF_VARS']
中引用,并且可以在文件
typo3conf/LocalConfiguration.php
typo3conf/AdditionalConfiguration.php
中定义 将本地化值映射到定义的局部值(即de_de、en_GB、en_US)所需的类注册如下:

$GLOBALS['TYPO3\u CONF\u VARS']['SYS']['routing']['aspects']['LocaleModifier']=\TYPO3\CMS\Core\routing\aspects\LocaleModifier::class;
在那里定义自己的类提供了提供附加功能的选项

可以定义哪些其他路由相关类?
路由机制相当复杂,因此存在几个易于替换的类。
要获得预定义和可替换类的概述,您可以验证
通过打开
模块
系统
->
配置
,在页面顶部的下拉字段中选择了
$GLOBALS['TYPO3\u CONF\u VARS'](全局配置)

在当前版本3-9.5.5中,配置了以下默认类

//方面
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['LocaleModifier']=TYPO3\CMS\Core\routing\aspects\LocaleModifier::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['PersistedAliasMapper']=TYPO3\CMS\Core\routing\aspects\PersistedAliasMapper::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['PersistedPatternMapper']=TYPO3\CMS\Core\routing\aspects\PersistedPatternMapper::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['aspects']['StaticRangeMapper']=TYPO3\CMS\Core\routing\aspects\StaticRangeMapper::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['aspects']['StaticValueMapper']=TYPO3\CMS\Core\routing\aspects\StaticValueMapper::class;
//增强剂
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['enhancers']['Extbase']=TYPO3\CMS\Extbase\routing\extbasepluginhancer::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\pluginhancer::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['enhancers']['Simple']=TYPO3\CMS\Core\routing\Enhancer\SimpleEnhancer::class;

目前,我认为没有必要编写自己的解决方案,但如果您已经编写了一个,请随意发布一个作为答案。

在这里查找“LOCALEMODIFIER”;这就是你要找的吗?@RiccardoDeContardi是的,谢谢,它在
LOCALEMODIFIER
一章中。仍然可以通过locallang文件“翻译”它吗?无论如何,回答一下,这样我就可以投票了;-)仅链接的答案可能会被删除;-)@里卡多,也许你有兴趣看看我自己的答案;-)