webexcess/redirecthandler-localization

创建快捷方式,该快捷方式将重定向到访客匹配的语言和区域维度。

1.1.0 2022-01-07 10:33 UTC

This package is auto-updated.

Last update: 2024-09-13 07:38:47 UTC


README

Logo Latest Stable Version License

此软件包允许创建Neos.RedirectHandler快捷方式,该快捷方式会重定向到访客匹配的语言和区域维度。

安装

composer require webexcess/redirecthandler-localization

配置

  • dimensionIdentifiers.linguistic (字符串)
    • 您的语言维度的键,默认:'language'
  • dimensionIdentifiers.regional (字符串)
    • 您的区域维度的键,默认:未设置
  • overwriteDefaultDimensionUriSegment (数组)
    • “维度标识符:默认维度URI段”的列表:默认:空
    • 使用此功能来覆盖每个维度的默认URI段
    • 示例: overwriteDefaultDimensionUriSegment.language: 'en'
  • ipinfoToken (字符串)
    • 到ipinfo.io webservice的令牌,默认:''(用于非商业用途)
    • 如果您每天需要超过1,000个请求,请添加您的令牌
    • 禁用令牌,以使用pecl geoip
    • 或实现自己的LocalizationInterface实现

使用方法

而不是将“目标URI路径”添加到“讲话URL”,添加节点标识符,例如:node://ad798967-8662-4c6f-b1d1-4c8188038d23

flow redirect:add source node://ad798967-8662-4c6f-b1d1-4c8188038d23 302

或使用WebExcess.RedirectHandler.Backend软件包。

简单示例

具有语言维度的网站。

现有维度配置

Neos:
  ContentRepository:
    contentDimensions:
      language:
        label: Language
        icon: icon-language
        default: en
        defaultPreset: en
        presets:
          de:
            label: German
            values:
              - de
              - en
            uriSegment: de
          fr:
            label: French
            values:
              - fr
              - en
            uriSegment: fr
          it:
            label: Italian
            values:
              - it
              - en
            uriSegment: it

RedirectHandler.Localization配置

无需配置。

高级示例

使用ipinfo.io地理定位访客IP地址的语言和国家维度网站。

现有维度配置

Neos:
  ContentRepository:
    contentDimensions:
      language:
        label: Language
        icon: icon-language
        default: en
        defaultPreset: en
        presets:
          de:
            label: German
            values:
              - de
              - en
            uriSegment: de
          fr:
            label: French
            values:
              - fr
              - en
            uriSegment: fr
          it:
            label: Italian
            values:
              - it
              - en
            uriSegment: it
          # ...
          en:
            label: English
            values:
              - en
            uriSegment: en
      country:
        label: Country
        icon: icon-globe
        default: GLOBAL
        defaultPreset: GLOBAL
        presets:
          GLOBAL:
            label: Global
            values:
              - GLOBAL
            uriSegment: ''
          CH:
            label: Schweiz
            values:
              - CH
              - GLOBAL
            uriSegment: CH
            constraints:
              language:
                '*': false
                de: true
                fr: true
                it: true
                en: true
          DE:
            label: Deutschland
            values:
              - DE
              - GLOBAL
            uriSegment: DE
            constraints:
              language:
                '*': false
                de: true
                en: true
          # ...
          ZA:
            label: 'South Africa'
            values:
              - ZA
              - GLOBAL
            uriSegment: ZA
            constraints:
              language:
                '*': false
                en: true

RedirectHandler.Localization配置

Objects.yaml

WebExcess\RedirectHandler\Localization\Service\LocalizationInterface:
  className: WebExcess\RedirectHandler\Localization\Service\LanguageAndCountryLocalization

Settings.yaml

WebExcess:
  RedirectHandler:
    Localization:
      dimensionIdentifiers:
        linguistic: 'language'
        regional: 'country'
      overwriteDefaultDimensionUriSegment:
        country: 'CH'
      ipinfoToken: '1234567890'

自定义示例

您可以添加自己的LocalizationInterface实现。

在getTargetContext函数中,您只需返回一个有效的上下文数组即可,例如

Array
(
    [dimensions] => Array
        (
            [language] => Array
                (
                    [0] => de
                    [1] => en
                )

            [country] => Array
                (
                    [0] => CH
                    [1] => GLOBAL
                )

        )

    [targetDimensions] => Array
        (
            [language] => de
            [country] => CH
        )

)

webexcess GmbH开发

Blaser Swisslube AG赞助