定制 werkraum/deepl-translate-slim 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

werkraum/deepl-translate-slim

Composer 安装命令:

composer require werkraum/deepl-translate-slim

包简介

Translate all your pages on demand, without additional configuration. You do not need to set up more than one language in TYPO3. Enable Translation targets in your site configuration and display a language menu with our Menu Integration and you are ready to go.

README 文档

README

Translate all your pages on demand, without additional configuration. You do not need to set up more than one language in TYPO3. Enable Translation targets in your site configuration and display a language menu with our Menu Integration and you are ready to go.

  • Pages are only translated on demand
    • a middleware processes the response from TYPO3 and has it translated by DeepL
    • the translation process can be customized to your needs Custom Translation Processing
  • all translation targets are validated
    • e.g. if you disabled DK it is not possible to bypass this value
  • search bots are excluded by default (otherwise they could use up you api translation volume)
  • all fetched translations are stored in a separate cache (to further protect you api volume)

Further Infos

Demo Link (german)

first News (german)

https://werkraum.net/typo3-deepl-integration (german)

Installation

composer require werkraum/deepl-translate-slim

Extension Setup

You have to provide an authenticationKey. Make sure to set the API Type to pro if you have a pro account.

deepl_extension_settings.png

Global Configuration Values

Key Description
authenticationKey The authentication Key for the DeepL Api Deepl API Key
host The API Type. Free and Pro have different Endpoints. Free and Pro
formality See Deepl API Reference
ignoreTags See Deepl API Reference
splitSentences See Deepl API Reference
preserveFormatting See Deepl API Reference
nonSplittingTags See Deepl API Reference
outlineDetection See Deepl API Reference
splittingTags See Deepl API Reference
clearCache See Caching

Site Configuration Values

Name Key Description
(default/fallback) Source Language default_deepl_source_language The source language DeepL will use to translate from. Can be disabled for each language. See languages.
(default/fallback) Allowed targets default_deepl_allowed_languages Add all allowed languages as alternate links. (clear the page cache to make this change take effect!)
Hreflang deepl_hreflang Only this languages will be offered for translation. Can be changed for each language. See languages.
Exclude Elements deepl_exclude_elements_by_selector Exclude HTML elements from translation by CSS3 Selector (comma-separated!)
Split content deepl_split_content_by_selectors DeepL has a content-length limit per translation request so we need to split our html into parts. Specify parts of your HTML by a comma-separated list of CSS3 selectors which can be translated separately. e.g. "#page-header,#page-content,#page-footer"
Replace links deepl_replace_links Add the language param "deepl" to all links?
Skip links deepl_replace_links_attribute Yes/No
Translated by machine placeholder deepl_translated_by_machine You have the following placeholder: {source}, {target}, {originalLink}
Target for the Translated by machine placeholder deepl_translated_by_machine_target Please specify an html element with an ID
Translate the Translated by machine placeholder deepl_translate_translated_by_machine Yes/No
Recaptcha Protection deepl_recaptcha Enable recaptcha verification to allow access to translated content.
Recaptcha Verify Page deepl_recaptcha_redirect_to_page PAge to redirect the user to verify their access via recaptcha. The configured page has to display the recaptcha verify plugin.

Menu Integration

The extension has a custom \Werkraum\DeeplTranslate\DataProcessing\DeepLMenuProcessor to provide the enabled DeepL translation targets. It provides the same values as the \TYPO3\CMS\Frontend\DataProcessing\LanguageMenuProcessor

dataProcessing {
  10 = Werkraum\DeeplTranslate\DataProcessing\DeepLMenuProcessor
  10 {
    as = menu
  }
}
<html data-namespace-typo3-fluid="true"
      xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
>
<nav class="nav languagenav text-uppercase notranslate">
    <f:for each="{menu}" as="item" iteration="iter">
        <a class="nav-link" href="{item.link}" hreflang="{item.hreflang}" rel="alternate nofollow" title="{item.title}">
            <span>{item.title}</span>
        </a>
    </f:for>
</nav>
</html>

Caching

The extension has its own cache to ensure that translations are retained in the system even if the content of the pages changes. The service is not free of charge and should be used sparingly. Nevertheless, this cache can be checked and emptied:

deepl_menu_clear_cache.png

You can enable cacheClear in the extension configuration to always flush the translations on page or page content change. By default it is disabled.

A dedicated view in the InfoModule provides a detailed overview of all cached pages.

deepl_info_module_cache_overview.png

Custom Translation Processing

You can customize and extend the translation process by implementing a custom DocumentProcessor with the Interface \Werkraum\DeeplTranslate\DocumentProcessor\DocumentProcessorInterface.

Look into ReplaceLinksProcessor.php to see it in action.

SEO and Bots

To save DeepL resources and avoid spamming the translation service, we use the following rules:

  • search bots are excluded by default (otherwise they could use up your api translation volume)
  • all fetched translations are stored in a separate cache (to further protect your api volume)

You should exclude all Urls with deepl from your robots.txt file. For example:

User-agent: *
Disallow: /*?deepl=/
Disallow: /*&deepl=/

werkraum/deepl-translate-slim 适用场景与选型建议

werkraum/deepl-translate-slim 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 334 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 06 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 werkraum/deepl-translate-slim 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 334
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2024-06-26