Giter Club home page Giter Club logo

gettext's Introduction

Gettext

Created by Oscar Otero http://oscarotero.com [email protected]

GNU Affero GPL version 3. http://www.gnu.org/licenses/agpl-3.0.html

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

Features:

  • Written in php 5.3
  • Extensible with plugins
  • Uses the PSR-0 autoloader standard

Contains the following classes:

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

Extractors

The extrators are static classes that extract the gettext values from any source and return a Gettext\Entries instance with them.

  • Gettext\Extractors\File - Scan a file and search for __() and __e() functions to collect all gettext strings
  • Gettext\Extractors\Po - Parse a PO file
  • Gettext\Extractors\Mo - Parse a MO file

Generators

Generators take a Gettext\Entries instance and export the data in any format.

  • Gettext\Generators\Mo - Generate a Mo file
  • Gettext\Generators\Po - Generate a Mo file
  • Gettext\Generators\Php - Generate a Php file (that returns an array with all values)

HOW TO USE?

First, lets scan a Po file:

use Gettext\Extractors\Po as PoExtractor;

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

Now, we can edit some translations:

$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/:

use Gettext\Generators\Php as PhpGenerator;
use Gettext\Generators\Jed as JedGenerator;

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

Now we can use this translations into our code:

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:

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/)

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

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

TO-DO

  • Jed and Php Extractors
  • Create a generic autoextractor and autogenerator
  • Complete the File extractor
  • Custom plural parser

gettext's People

Contributors

oscarotero avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.