leaseweb/gettext-translation-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

leaseweb/gettext-translation-bundle

Composer 安装命令:

composer require leaseweb/gettext-translation-bundle

包简介

Easy to use and native (faster) gettext translation support

README 文档

README

The LswGettextTranslationBundle adds gettext translation support to your Symfony4 application. It is aimed to be faster and more user-friendly than the built-in translation support of Symfony4.

Requirements

  • PHP with gettext support
  • Symfony 4+

Installation

Installation is broken down in the following steps:

  1. Download LswGettextTranslationBundle using composer
  2. Enable the Bundle
  3. Install the needed locales
  4. Set the language in your application

Step 1: Download LswGettextTranslationBundle using composer

Add LswGettextTranslationBundle in your composer.json:

{
    "require": {
        "leaseweb/gettext-translation-bundle": "*",
        ...
    }
}

Now tell composer to download the bundle by running the command:

$ php composer.phar update leaseweb/gettext-translation-bundle

Composer will install the bundle to your project's vendor/leaseweb directory.

Step 2: Enable the bundle

Enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Lsw\GettextTranslationBundle\LswGettextTranslationBundle(),
    );
}

Step 3: Install the needed locales

As described here you can list the locales that you have installed on your (Linux) system with the command 'locale -a'. If you want to support Dutch, English and German you should execute the following commands:

sudo locale-gen nl_NL.UTF-8
sudo locale-gen en_US.UTF-8
sudo locale-gen de_DE.UTF-8

More language codes can be found here

Step 4: Set the language in your application

Use the standard $request->setLocale('en'); to set the locale in your application.

Edit the following file to define 2 letter shortcuts for the locales (this is recommended):

Lsw/GettextTranslationBundle/Resources/config/config.yml

Usage

Usage is broken down in the following steps:

  1. Use gettext (convenience) functions in your code
  2. Extract the strings from a bundle that need to translated by gettext (.pot file)
  3. (First time only) Initialize the languages you want to support in the bundle (.po file)
  4. (Skip first time) Update the language (.po) files with the new gettext template (.pot) file
  5. Translate the language files using the excellent Poedit application
  6. Combine all translations into one file (.mo file)

Step 1: Use gettext (convenience) functions in your code

You can use the following functions:

  • _($text) Shortcut for gettext
  • _n($textSingular,$textPlural,$n) Shortcut for ngettext
  • __($format,$args,...) Shortcut for sprintf(_($format),$args,...))
  • __n($formatSingular,$formatPlural,$n,$args,...) Shortcut for sprintf(_n($formatSingular,$formatPlural,$n),$args,...))

Step 2: Extract the strings from a bundle

Use the ./app/console gettext:bundle:extract command to search a bundle for translation strings and to store them into a gettext template (.pot) file.

Step 3: (First time only) Initialize the languages you want to support

Use the ./app/console gettext:bundle:initialize command to copy the gettext template (.pot) file into the language specific (.po) files.

Step 4: (Skip first time) Update the gettext language (.po) files with the template

Use the Poedit application to load a gettext language (.po) file. Choose the "Update from template" option and point Poedit to the generated gettext template (.pot) file. Review and confirm the changes.

Step 5: Translate the language files using the excellent Poedit application

Use the Poedit application to load a gettext language (.po) file. Translate all missing strings (shown in blue) and check and correct all fuzzy translated strings (shown in yellow).

Step 6: Combine all translation

Use the ./app/console gettext:combine command combine all gettext language (.po) files into one compiled gettext (.mo) file.

leaseweb/gettext-translation-bundle 适用场景与选型建议

leaseweb/gettext-translation-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 60.75k 次下载、GitHub Stars 达 24, 最近一次更新时间为 2012 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 24
  • Watchers: 22
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-11-23