承接 letkode/locale-bundle 相关项目开发

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

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

letkode/locale-bundle

Composer 安装命令:

composer require letkode/locale-bundle

包简介

Locale provider, listener and translatable field applier for Symfony applications

README 文档

README

Locale provider, listener and translatable field applier for Symfony applications.

Installation

composer require letkode/locale-bundle

Symfony Flex will register the bundle automatically. If not using Flex, add it manually:

// config/bundles.php
return [
    Letkode\LocaleBundle\LetkodeLocaleBundle::class => ['all' => true],
];

Configuration

Create config/packages/letkode_locale.yaml:

letkode_locale:
    default_locale: '%env(APP_DEFAULT_LOCALE)%'
    supported_locales: '%env(json:APP_SUPPORTED_LOCALES)%'

Add the corresponding .env variables:

APP_DEFAULT_LOCALE=en
APP_SUPPORTED_LOCALES=["en","es"]

Contents

LocaleProvider

Resolves the active locale for the current request. Inject it in services that need locale-awareness.

public function __construct(private readonly LocaleProvider $localeProvider) {}

public function doSomething(): void
{
    $locale = $this->localeProvider->getLocale(); // 'en' | 'es' | ...
}

LocaleListener

Kernel event listener (priority 20) that sets $request->setLocale() on every request. Reads from:

  1. _locale query parameter
  2. Accept-Language header (first matching supported locale)
  3. Configured default_locale as fallback

TranslatableFieldApplier

Applies translated values from a translations jsonb map to entity fields for the active locale.

// Entity has: public array|null $translations = null; (via HasTranslationsTrait)
// translations = {"en": {"name": "Module"}, "es": {"name": "Módulo"}}

$this->translatableFieldApplier->apply($entity, ['name']);
// $entity->name is now set to the locale-specific value

Requirements

  • PHP ^8.4
  • Symfony ^7.0 || ^8.0

License

MIT — see LICENSE.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固