lafourchette/l10n-bundle

A bundle to manage localization

Installs: 73 810

Dependents: 0

Suggesters: 0

Security: 0

Stars: 8

Watchers: 71

Forks: 4

Open Issues: 0

Type:symfony-bundle

v1.7.1 2017-04-28 15:12 UTC

README

Build Status Scrutinizer Code Quality Code Coverage

Overview

The aim of L10nBundle is to provide a very simple way to deal with L10N, like I18N with Symfony translator.

L10N data can be store wherever you want. Currently, L10nBundle supports YaML file and MongoDb.

Configuration

Global

l10n:
    localization_fallback: en # Fallback localization, used when no explicit Localization is asked or localization not found. Value may be string or integer
    locale_fallback: en_US # Fallback locale, to manage L10N values
    manager: yaml # The name of the manager you want to use currently yaml or mongodb

You can use the parameters of your symfony configuration in your values. Example:

#parameters.yml
parameters:
    my_environment_extension: local

#l10n.yml
l10n:
    my_url:
        gb: www.domain.%my_environment_extension%

The value will be resolved like this:

my_url => www.domain.local

yaml

yaml:
    data_file: /path/to/main.yaml

You can import files

imports:
    - { resource: "../../src/Bundle/MyBundle/Resources/translations/l10n.yml" }

Configuration is under l10n key

l10n:
    registration:
        label:
            fr: FRA
            es: SPA
        name:
            fr: french name
            es: spanish name

You can use the keys registration.label and registration.name.

Simple translation is provided

Use an array as value:

l10n:
    registration.label:
        fr:
            - {locale: fr, value: FRA_fr}
            - {locale: en, value: FRA_en}

mongodb

mongodb:
    host: 127.0.0.1
    port: 27017
    username: test
    password: T3$t
    database: test_db

Usage

PHP

Example in a controler

$l10n = $this->getContainer()->get('l10n_bundle.business.l10n_provider');
$l10n->getL10n('key', 'idLoc');

Twig

In a twig template you can use the l10n filter

{{ 'key'|l10n }}

You can also provide parameters such as the default localization and/or the locale.

{{ 'key'|l10n('es', 'ca') }}