survos/libre-translate-bundle
Composer 安装命令:
composer require survos/libre-translate-bundle
包简介
关键字:
README 文档
README
A bundle based on jefs42/libretranslate
Setup
Install libretranslate local
Demo
symfony new TranslationDemo --webapp && cd TranslationDemo composer req survos/libre-translate-bundle bin/console make:controller AppController
dokku storage:mount /mnt/volume-1/project-data/trans/data:/app/data chown -R 32767:32767 /mnt/volume-1/project-data/trans
Open AppController.php and add
#[Route('/{target}', name: 'app_homepage')] public function home( LibreTranslate $libreTranslate, CacheInterface $cache, string $target = 'es'): Response { $url = 'https://saurav.tech/NewsAPI/top-headlines/category/health/in.json'; $data = $cache->get(md5($url), fn(CacheItem $item) => json_decode(file_get_contents($url))); $translations = []; foreach ($data->articles as $idx => $article) { $translations[] = $cache->get(md5($article->title).$target, fn(CacheItem $cacheItem) => $libreTranslate->Translate($article->title, target: $target) ); } return $this->render('app/index.html.twig', [ 'headlines' => $data, 'translations' => $translations, 'languages' => $libreTranslate->Languages() ]); }
Open app/index.html and replace the body with
{% for locale, lang in languages %}
<a href="{{ path('app_homepage', {target: locale}) }}">
{{ lang }}
</a>
|
{% endfor %}
<table>
<tbody>
{% for idx, headline in headlines.articles %}
<tr>
<td>
<img style="width: 100px" src="{{ headline.urlToImage }}" />
</td>
<td>
{{ headline.title }}
<br />
<i>
{{ translations[idx] }}
</i>
</td>
</tr>
{% endfor %}
</tbody>
</table>
Run the symfony server to see the results:
symfony server:start
Generating code classes
Install java 11 or higher
Get CLI jar:
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/6.6.0/openapi-generator-cli-6.6.0.jar -O openapi-generator-cli.jar
Run command to generate classes:
java -jar openapi-generator-cli.jar generate -i libretranslate.json -g php -o ~/projects/survos/test-libre-gen/
Database
survos/libre-translate-bundle 适用场景与选型建议
survos/libre-translate-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.69k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony-ux」 「symfony6」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 survos/libre-translate-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 survos/libre-translate-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 survos/libre-translate-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Sylius eCommerce administration panel component.
Doctrine Block management made easy
Symfony Bundle to handle migrations between multiple bundles
Symfony bundle for the Rekapager library
File input dropzones multiple for Symfony Forms
Symfony UX Table with search, filter and sorting options.
统计信息
- 总下载量: 1.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-13