saxulum/saxulum-translation-provider

Saxulum Translation Provider (yaml)

Installs: 480

Dependents: 3

Stars: 1

Watchers: 1

Forks: 1

Language: PHP

2.0.1 2014-10-10 09:59 UTC

README

works with plain silex-php

Build Status Total Downloads Latest Stable Version Scrutinizer Code Quality

Features

  • Register translations

Requirements

  • php >=5.3
  • Symfony Config Component >=2.3
  • Symfony Finder Component >=2.3
  • Symfony Translation Component >=2.3
  • Symfony Yaml Component >=2.3

Installation

Through Composer as saxulum/saxulum-translation-provider.

Preparation (for non silex users) Debug value is needed
$container['debug'] = true; // or false
Define translator service
use Symfony\Component\Translation\Translator;

$container['translator'] = function () {
    return new Translator('en');
};

Or if you load silex/silex as a dependency you can also use the TranslationServiceProvider.

use Silex\Provider\TranslationServiceProvider;

$container['locale'] = 'en';
$container->register(new TranslationServiceProvider());
For all users With translation cache (faster)
use Saxulum\Translation\Silex\Provider\TranslationProvider;

$container->register(new TranslationProvider(), array(
    'translation_cache' => '/path/to/cache'
));
  • debug == true: the cache file will be build at each load
  • debug == false: the cache file will be build if not exists, delete it if its out of sync
Without translation cache (slower)
use Saxulum\Translation\Silex\Provider\TranslationProvider;

$container->register(new TranslationProvider());

Usage

Add the translation paths
$container['translation_paths'] = $container->extend('translation_paths', function ($paths) {
    $paths[] = '/path/to/the/translations';

    return $paths;
});

Usage with Twig templates

To get access to the |trans filter in Twig templates, you must register the translator first and then add the TwigServiceProvider from silex/silex. You will also have to require the symfony/twig-bridge package.

use Silex\Provider\TwigServiceProvider;

$this->register(new TwigServiceProvider(), [
    'twig.path'    => array(__DIR__.'/../views'),
    'twig.options' => array('cache' => $cacheDir),
]);