承接 lochmueller/language-detection 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lochmueller/language-detection

Composer 安装命令:

composer require lochmueller/language-detection

包简介

Modern language detection middleware for TYPO3. Based on PSR-7, PSR-14 & PSR-15.

README 文档

README

Meta: start with why Latest Stable Version Total Downloads License Crowdin Average time to resolve an issue Percentage of issues still open

Compatibility: TYPO3 TYPO3 TYPO3

Quality: Test codecov Scrutinizer Code Quality PHPStan

Support: Donate contributions welcome Plant Tree

Table of Contents

  1. Why?
  2. Installation
  3. Configuration
  4. Event Structure
    1. CheckLanguageDetectionEvent
    2. DetectUserLanguagesEvent
    3. NegotiateSiteLanguageEvent
    4. BuildResponseEvent
  5. Troubleshooting
  6. Dev
  7. Contribution
  8. Licence

Why?

Language Detection should be easy & simple to integrate and powerfully in development! TYPO3 Core do not handle language detection via client information. EXT:languag_detection use a PSR-15/PSR-7 middleware/request (TYPO3 Documentation) to handle a language detection logic via PSR-14 events(TYPO3 Documentation). Very flexible! Give it a try and checkout the future of language detection!

Installation

composer require lochmueller/language-detection

Configuration

Use the site configuration module to configure the language detection. Just enable it, and it will work :) There are several configuration options for the Site configuration that handle the control events. The following screenshot show the options of the detection configuration.

Configuration

Event Structure

There are four central PSR-14 events that control the language detection. The attached list explain the different events and the default listener. The events are ordered in the execution order.

Diagram Request flow

CheckLanguageDetectionEvent

Check if the language detection should execute by the extension. You can register listeners for this event and call "disableLanguageDetection" on the event object to disable the language detection.

Default-Listener:

Name Description
BackendUserCheck Check if a backend user call the language detection and disable the redirect (respect "disableRedirectWithBackendSession" config)
BotAgentCheck Check if a bot call the language detection and disable the redirect
EnableCheck Check if the Language Detection is enabled in the current Site
FromCurrentPageCheck Check the referrer and disable the redirect if the user comes from the current site
PathCheck Check if the user call "/" and disable the redirect for other paths (respect "allowAllPaths" configuration)
WorkspacePreviewCheck Check if the page is a workspace preview and disable the redirect

DetectUserLanguagesEvent

This event collect user information to get the user languages. You can register your own detections and manipulate the data via "getUserLanguages" and "setUserLanguages".

Default-Listener:

Name Description
BrowserLanguageDetect Get the users "accept-language" languages
GeoPluginDetect Send the IP to ip-api.com and add the language of the location to the checked languages (respect "addIpLocationToBrowserLanguage" configuration)
MaxMindDetect Use MaxMind database or webservice to get the country information

Please keep data privacy in mind in case of the "IpLanguage" Listener!

NegotiateSiteLanguageEvent

This event calculates the best matching page language for the user. If you build your own listener. Please use "setSelectedLanguage" on the event. If a language is already selected the default listener will be skipped.

Default-Listener:

Name Description
DefaultNegotiation Check the Locale and TwoLetterIso of the TYPO3 languages against the user languages of the previous event
FallbackNegotiation Handle a fallback, if there are no matches by the default negotiation

BuildResponseEvent

The last event build the middleware response. You can overwrite this step. You have to use "setResponse" to set the response.

Default-Listener:

Name Description
DefaultResponse Build the response object and respect the "redirectHttpStatusCode" config

Troubleshooting

There are missing or wrong languages in the detection process. Why?

Do you check in incognito mode? The browser will not send all languages in incognito mode. So "wrong results" are possible. Please check the request header to TYPO3 in detail. Otherwise, perhaps the DefaultNegotiation do not handle the "best fitting language" selection process for your needs?

Why the redirect not work on subpages?

The middleware is early in the middleware stack. There is no concept of links and translations (or even page UID). Furthermore, it is recommended not redirect on subpages. A user that call a subpage first bookmark the page or search in a search engine. In both cases the user already get the right language. I suggest hreflang tags so search engines get the right language of the content https://developers.google.com/search/docs/advanced/crawling/localized-versions

Dev

Run all code standards

docker run --rm -it --volume $(pwd):/app prooph/composer:8.0 -d /app code:all

Execute tests with PHP 8.0:

docker run --rm -it --volume $(pwd):/app prooph/composer:8.0 -d /app test:unit

With coverage:

docker run --rm -it --volume $(pwd):/app cicnavi/dap:80 /app/.Build/bin/phpunit -c /app/phpunit.xml --coverage-text --testdox --coverage-html=/app/var/phpunit

Run Mutation tests:

docker run --rm -it --workdir=/app/ --volume $(pwd):/app cicnavi/dap:80 /app/.Build/bin/infection -c /app/phpunit.xml

Contribution

Thanks all for the great contribution to the project!

GitHub Contributors Image

Licence

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

lochmueller/language-detection 适用场景与选型建议

lochmueller/language-detection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 95.95k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2020 年 09 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「language」 「detection」 「TYPO3 CMS」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 lochmueller/language-detection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 lochmueller/language-detection 我们能提供哪些服务?
定制开发 / 二次开发

基于 lochmueller/language-detection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 95.95k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 19
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 15
  • Watchers: 1
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2020-09-04