digicomp/flow-translation-endpoint
Composer 安装命令:
composer require digicomp/flow-translation-endpoint
包简介
A simple endpoint providing XLIFF translations as string
关键字:
README 文档
README
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.
digicomp/flow-translation-endpoint 适用场景与选型建议
digicomp/flow-translation-endpoint 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.6k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 08 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「flow」 「json」 「translation」 「Neos」 「xliff」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 digicomp/flow-translation-endpoint 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 digicomp/flow-translation-endpoint 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 digicomp/flow-translation-endpoint 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
A custom URL rule class for Yii 2 which allows to create translated URL rules
Put images nicley in a row
A Laravel Eloquent model trait for translatable resource
Create link to static resources with cache-breaking segment based on md5 of the file
ext-json wrapper with sane defaults
统计信息
- 总下载量: 1.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-15