2017 © Pedro Peláez
 

symfony-bundle gettext-translation-bundle

Easy to use and native (faster) gettext translation support

image

leaseweb/gettext-translation-bundle

Easy to use and native (faster) gettext translation support

  • Monday, February 12, 2018
  • by LeaseWeb
  • Repository
  • 13 Watchers
  • 25 Stars
  • 31,731 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 10 Forks
  • 6 Open issues
  • 7 Versions
  • 2 % Grown

The README.md

LswGettextTranslationBundle

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., (*1)

Requirements

  • PHP with gettext support
  • Symfony 4+

Installation

Installation is broken down in the following steps:, (*2)

  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:, (*3)

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

Now tell composer to download the bundle by running the command:, (*4)

``` bash $ php composer.phar update leaseweb/gettext-translation-bundle, (*5)


Composer will install the bundle to your project's `vendor/leaseweb` directory. ### Step 2: Enable the bundle Enable the bundle in the kernel: ``` php <?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:, (*6)

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](http://lh.2xlibre.net/locales/)

### 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 ```, (*7)

Usage

Usage is broken down in the following steps:, (*8)

  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:, (*9)

  • _($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., (*10)

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., (*11)

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., (*12)

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)., (*13)

Step 6: Combine all translation

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

The Versions

12/02 2018

dev-master

9999999-dev http://www.leaseweblabs.com

Easy to use and native (faster) gettext translation support

  Sources   Download

MIT

The Requires

 

translation i18n gettext

12/02 2018

v1.1.1

1.1.1.0 http://www.leaseweblabs.com

Easy to use and native (faster) gettext translation support

  Sources   Download

MIT

The Requires

 

translation i18n gettext

17/01 2017

v1.1.0

1.1.0.0 http://www.leaseweblabs.com

Easy to use and native (faster) gettext translation support

  Sources   Download

MIT

The Requires

 

translation i18n gettext

30/05 2016

v1.0.3

1.0.3.0 http://www.leaseweblabs.com

Easy to use and native (faster) gettext translation support

  Sources   Download

MIT

The Requires

 

translation i18n gettext