PHPackages                             perfectneeds/locale-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. perfectneeds/locale-bundle

ActiveSymfony-library[Localization &amp; i18n](/categories/localization)

perfectneeds/locale-bundle
==========================

manage multi languages on project

2.0.8(3y ago)04.6k2MITHTMLPHP ^7.3 || ^8.0

Since May 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/PerfectNeeds/locale-bundle)[ Packagist](https://packagist.org/packages/perfectneeds/locale-bundle)[ Docs](http://perfectneeds.github.com)[ RSS](/packages/perfectneeds-locale-bundle/feed)WikiDiscussions 1.0 Synced 6d ago

READMEChangelogDependencies (6)Versions (20)Used By (2)

PerfectNeeds LocaleBundle
=========================

[](#perfectneeds-localebundle)

Very simple bundle that allows you to translate your entities.

##### Reference Repo.

[](#reference-repo)

Installation:
-------------

[](#installation)

- composer require perfectneeds/locale-bundle "~1.0"
- Register bundle in AppKernel.php: `new VM5\EntityTranslationsBundle\VM5EntityTranslationsBundle()`
- Copy LocaleBundle inside your ptoject in `src/PN/Bundle`
- Register bundle in AppKernel.php: `new PN\LocaleBundle\LocaleBundle()`
- Add messages file into `app/Resources/translations` for each language called messages.{LOCALE}.php (ex. messages.ar.php)
- You must add this code in config.yml:

```
parameters:
    locale: en
    app.locales: en|ar|

doctrine:
   orm:
        # search for the "ResolveTargetEntityListener" class for an article about this
        resolve_target_entities:
            VM5\EntityTranslationsBundle\Model\Language:
```

### Change the Locale in API methods

[](#change-the-locale-in-api-methods)

```
$this->get('vm5_entity_translations.translator')->setLocale('ar'); //translate entities
$this->get('translator')->setLocale('ar'); // translates messages
```

### Routing example

[](#routing-example)

```
cms:
    resource: "@CMSBundle/Controller/FrontEnd/"
    type:    annotation
    prefix: /{_locale}
    defaults:  {_locale: '%locale%' }
    requirements:
        _locale: '%app.locales%'

```

### Example entities:

[](#example-entities)

```
