2017 © Pedro Peláez
 

library tee

PHP 5.3+ translation framework, similar to Gettext

image

jamwaffles/tee

PHP 5.3+ translation framework, similar to Gettext

  • Tuesday, February 11, 2014
  • by JamWaffles
  • Repository
  • 1 Watchers
  • 2 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Tee

Composer-compatible translation framework for PHP 5.3+ supporting multiple translation backends., (*1)

Installation

Tee can be installed through Composer by adding it to your dependencies like this:, (*2)

{
    "require": {
        "jamwaffles/tee": "dev-master"
    }
}

Configuration

Make sure to include the Composer autoloader. You can then globally configure Tee as follows:, (*3)

require_once 'vendor/autoload.php';

use \Tee\Translator as Trans;

Trans::configure(array(
    'adapter' => '\\Tee\\Adapter\\JSON',
    'adapterConfig' => array('translations' => 'example_translations/'),
    'locale' => 'de'
));

Tee is aliased to Trans here to make things easier., (*4)

Tee is bundled with the \Tee\Adapter\JSON JSON-based adapter by default. You can write your own by extending the \Tee\TeeAdapter interface., (*5)

Usage

Tee can be used as a namespaced static class as \Tee\Translator like this:, (*6)

\Tee\Translator::configure(array( ... ));

$username = 'JamWaffles';
$someString = \Tee\Translator::translate("Hello, %s", $username);

Or with the convinence method, T(), like this in your templates:, (*7)

<h1><?= T("Account for %s", $username) ?></h1>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>

Adapters

JSON

The JSON adapter uses standard JSON files to store translations in a "original": "translation" format. For example:, (*8)

{
    "Hello world, my name is %s": "Hallo Welt, mein Name ist %s"
}

Configure Tee to use the \Tee\Adapter\JSON adapter like this:, (*9)

Trans::configure(array(
    'adapter' => '\\Tee\\Adapter\\JSON',
    'adapterConfig' => array('translations' => 'resources/languages/'),
    'locale' => 'de'        // Or whatever else
));

Pass an array to adapterConfig to specify where the translations will be stored. The locale value is the name of the translation file without the .json extension. The configuration above would look for a file at, (*10)

resources/languages/de.json

Todo

  • Documentation on the wiki
  • Modify JSON adapter file format to have a small config section so fallback languages can be specified
  • Add support for multiple caching mechanisms. Will look into supporting most common existing caching libraries. APC(u) will come first.
  • Better error reporting. Allow passing of logger instances?

The Versions

11/02 2014

dev-master

9999999-dev http://github.com/jamwaffles/Tee

PHP 5.3+ translation framework, similar to Gettext

  Sources   Download

The Requires

  • php >=5.3.0

 

translation i18n tee

11/02 2014

v0.0.3

0.0.3.0 http://github.com/jamwaffles/Tee

PHP 5.3+ translation framework, similar to Gettext

  Sources   Download

The Requires

  • php >=5.3.0

 

translation i18n tee

02/12 2013

0.0.1

0.0.1.0 http://github.com/jamwaffles/Tee

PHP 5.3+ translation framework, similar to Gettext

  Sources   Download

translation i18n tee