承接 digicomp/flow-translation-endpoint 相关项目开发

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

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

digicomp/flow-translation-endpoint

最新稳定版本:4.1.0

Composer 安装命令:

composer require digicomp/flow-translation-endpoint

包简介

A simple endpoint providing XLIFF translations as string

README 文档

README

Build status

This package is designed to help bringing needed translations to javascript components, without pushing them to the DOM in your views.

Other solutions, which would generate files available for usage in client scope, have the disadvantage that one would have to repeat the relativ complex overriding and merging logic of Flow. With this endpoint you can get the same content, as you would get, if you call the translation service with your translation id.

The main components are a CurrentHtmlLangViewHelper, which is intended to be used to fill the lang attribute of the html tag, so the frontend knows, which language is currently active (and is good practice anyway) and a TranslationRequestMiddleware, which will respond to any request, where the request path equals DigiComp.FlowTranslationEndpoint.reactOnPath (Default: "/xliff-units"), and search for unit patterns in the DigiComp.FlowTranslationEndpoint.getParameterName (Default: "idPatterns").

"idPatterns" is built with following syntax: packageName:catalogName|SEARCH_REGEX, ANOTHER PATTERN...

For example:

GET /xliff-units?idPatterns=Neos.Flow:Main|authentication.*

would return all translation keys from the main unit of Neos.Flow starting with "authentication" and would look like that:

{
    "Neos.Flow:Main": {
        "authentication.required": "Authentication required", 
        "authentication.username": "Username",
        "authentication.password": "Password", 
        "authentication.new-password": "New password",
        "authentication.login": "Login", 
        "authentication.logout": "Logout"
    }
}

To let the middleware know, in which langauge the translated units should be, you should set the correct Accept-Language-Header with your request, which you obtained from the lang attribute of the html element.

Given your HTML head looks like that:

<html lang="{translation:currentHtmlLang()}" data-xliff-uri="{translation:uri()}" data-xliff-parameter="{translation:parameterName()}">

Your JavaScript could look like that:

async function translate(idPatterns) {
    const uri = new URL(document.documentElement.dataset.xliffUri, document.location);
    uri.searchParams.set(document.documentElement.dataset.xliffParameter, idPatterns);
    const response = await fetch(uri, {headers: {
        'Accept': 'application/json',
        'Accept-Language': document.documentElement.lang,
    }});
    if (! response.ok) {
        return Promise.reject('Unexpected server response');
    }
    return await response.json();
}

Last but not least: Do not forget to have a lot of fun.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固