定制 locastic/symfony-translation-bundle 二次开发

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

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

locastic/symfony-translation-bundle

Composer 安装命令:

composer require locastic/symfony-translation-bundle

包简介

Symfony translation bundle

README 文档

README

Locastic Translation Bundle

This bundle gives the basis to allow translating your messages from any admin panel. You will now be able to create translation migrations, the same way you create your database migrations. It also provides a few services to help you expose and manage your translations.

Installation

composer require locastic/symfony-translation-bundle

Configuration

imports:
    - { resource: "@LocasticSyliusTranslationPlugin/Resources/config/config.yaml" }

locastic_sylius_translation:
    default_locale: en # The default locale to use
    locales: # The list locales supported by your application
        - en 

Note: This bundle supports locales the same way as Symfony, meaning that en will be the fallback for en_US and en_GB.

Usage

Creating a translation migration

<?php

declare(strict_types=1);

namespace App\TranslationMigrations;

use Locastic\SymfonyTranslationBundle\Provider\ThemesProviderInterface;
use Locastic\SymfonyTranslationBundle\TranslationMigration\AbstractTranslationMigration;

final class Version20230201074700 extends AbstractTranslationMigration
{
    public function up(): void
    {
        $this->addTranslation('test.translation', 'messages', 'en', 'This is a test translation', ThemesProviderInterface::NAME_DEFAULT);
    }
}

Then you can run the migration with the following command:

bin/console locastic:symfony-translation:migration:migrate

Note: down for migrations is not supported yet.

Exposing translations

You will need to create a controller to expose your translations. Here is an example:

<?php

declare(strict_types=1);

namespace App\Controller;

use Locastic\SymfonyTranslationBundle\Form\Type\SearchTranslationType;
use Locastic\SymfonyTranslationBundle\Model\SearchTranslation;
use Locastic\SymfonyTranslationBundle\Utils\SearchTranslationsUtilsInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;

final class IndexTranslationAction
{
    public function __construct(
        private SearchTranslationsUtilsInterface $searchTranslationsUtils,
        private Environment $twig,
        private FormFactoryInterface $formFactory,
    ) {
    }

    public function __invoke(Request $request): Response
    {
        $search = new SearchTranslation();
        $searchForm = $this->formFactory->create(SearchTranslationType::class, $search);
        $searchForm->handleRequest($request);

        $pagerFanta = $this->searchTranslationsUtils->searchTranslationsFromRequest($request, $search, $searchForm);

        return new Response($this->twig->render('{yourTemplate}', [
            'translations' => $pagerFanta,
            'resources' => $pagerFanta,
            'searchForm' => $searchForm->createView(),
        ]));
    }
}

And then create a template displaying your translations. Recommended way is to save translations via an AJAX and use the SaveTranslationsAction class to save them.

locastic/symfony-translation-bundle 适用场景与选型建议

locastic/symfony-translation-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.06k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 locastic/symfony-translation-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 6.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 6
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-30