2017 © Pedro PelĂĄez
 

library gettext

PHP - JS gettext conversor

image

wildalmighty/gettext

PHP - JS gettext conversor

  • Tuesday, September 10, 2013
  • by wildalmighty
  • Repository
  • 1 Watchers
  • 0 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 102 Forks
  • 0 Open issues
  • 2 Versions
  • 8 % Grown

The README.md

Gettext

Created by Oscar Otero http://oscarotero.com oom@oscarotero.com, (*1)

GNU Affero GPL version 3. http://www.gnu.org/licenses/agpl-3.0.html, (*2)

Gettext is a PHP library to import/export/edit gettext from PO, MO, PHP, JS files, etc., (*3)

Features:, (*4)

  • Written in php 5.3
  • Extensible with plugins

Contains the following classes:, (*5)

  • Gettext\Translation - Contains a translation definition
  • Gettext\Entries - A translations collection
  • Gettext\Translator - A gettext implementation for PHP

Extractors

The extrators are classes that extract the gettext values from any source and return a Gettext\Entries instance with them., (*6)

  • Gettext\Extractors\PhpCode - Scan a php file looking for all gettext functions to collect their strings
  • Gettext\Extractors\JsCode - Scan a javascript file looking for all gettext functions to collect their strings
  • Gettext\Extractors\PhpArray - Gets the strings from a php file that returns an array of values (complement of PhpArray generator)
  • Gettext\Extractors\Po - Gets the strings from PO files
  • Gettext\Extractors\Mo - Gets the strings from MO files

Generators

Generators take a Gettext\Entries instance and export the data in any of the following format., (*7)

  • Gettext\Generators\Mo - Generate a Mo file
  • Gettext\Generators\Po - Generate a Po file
  • Gettext\Generators\Jed - Generate a json file compatible with Jed library
  • Gettext\Generators\PhpArray - Generate a Php file that returns an array with all values

HOW TO USE?

First, lets scan a Po file:, (*8)

//Include the autoloader if you don't use composer or PSR-0 loader
include('myLibsFolder/Gettext/autoloader.php');

use Gettext\Extractors\Po as PoExtractor;

$translations = PoExtractor::extract('my-file.po');

Now, we can edit some translations:, (*9)

$translation = $translations->find(null, 'apples');

if ($translation) {
    $translation->setTranslation('MazĂĄns');
}

And export to a php file and a json file for use with Jed library (http://slexaxton.github.com/Jed/:, (*10)

use Gettext\Generators\PhpArray as PhpArrayGenerator;
use Gettext\Generators\Jed as JedGenerator;

PhpArrayGenerator::generateFile($translations, 'locate.php');
JedGenerator::generateFile($translations, 'locate.json');

Now we can use this translations into our code:, (*11)

use Gettext\Translator as Gt;

Gt::loadTranslations('locate.php');

echo Gt::gettext('apples'); //Returns MazĂĄs

You can use the translator functions, a short version of Gettext\Translator for more confort:, (*12)

echo __('apples'); //Returns MazĂĄs

__e('apples'); //echo MazĂĄs

And you can use the same translations in javascript with the Jed library (http://slexaxton.github.com/Jed/), (*13)

$.getJSON('locate.json', function (locale) {
    i18n = new Jed({
        locale_data: locale
    });

    alert(i18n.gettext('apples')); //alerts "MazĂĄs"
});

TO-DO

  • Custom plural parser
  • Working with domains

The Versions

10/09 2013

dev-master

9999999-dev https://github.com/oscarotero/Gettext

PHP - JS gettext conversor

  Sources   Download

AGPL-3.0

The Requires

  • php >=5.4.0

 

translation js i18n gettext

26/07 2013

dev-patch-1

dev-patch-1 https://github.com/oscarotero/Gettext

PHP - JS gettext conversor

  Sources   Download

AGPL-3.0

The Requires

  • php >=5.3.0

 

translation js i18n gettext