Skip to content

zeleznypa/jao-nettetranslator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 

Repository files navigation

#JAO NetteTranslator (cc)# Pavel Železný (2bfree), 2012 (www.pavelzelezny.cz)

Requirements

Nette Framework 2.0 or higher. (PHP 5.3 edition)

Documentation

Here will be my from scratch rewritten variant of great but old marten-cz/NetteTranslator what I used before.

Now here is just Gettex library to manipulate with gettext .po and .mo files.

Examples

1) Load dictionary from .po file

$dictionary = new GettextDictionary();
$dictionary->loadDictionary('./dictionary.po');
printf("<h2>Files:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->files,true)));
printf("<h2>Headers:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->getHeaders(),true)));
printf("<h2>Translations:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->getTranslations(),true)));

2) Alternative loading dictionary from .po file

$dictionary = new GettextDictionary('./dictionary.po');
printf("<h2>Files:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->files,true)));
printf("<h2>Headers:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->getHeaders(),true)));
printf("<h2>Translations:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->getTranslations(),true)));

3) Load dictionary from .mo file

$dictionary = new GettextDictionary();
$dictionary->loadDictionary('./dictionary.mo');
printf("<h2>Files:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->files,true)));
printf("<h2>Headers:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->getHeaders(),true)));
printf("<h2>Translations:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->getTranslations(),true)));

4) Alternative loading dictionary from .mo file

$dictionary = new GettextDictionary('./dictionary.mo');
printf("<h2>Files:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->files,true)));
printf("<h2>Headers:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->getHeaders(),true)));
printf("<h2>Translations:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->getTranslations(),true)));

5) Generating new dictionary

$dictionary = new GettextDictionary();

// Setting optional but basic headers.
$dictionary->setHeader('Project-Id-Version','Test dictionary 1.0');
$dictionary->setHeader('Language-Team','Elite translator monkeys <info@pavelzelezny.cz>');
$dictionary->setHeader('Plural-Forms','nplurals=3; plural=(n==1)? 0 : (n>=2 && n<=4)? 1 : 2;');
$dictionary->setHeader('Last-Translator','JAO NetteTranslator <info@pavelzelezny.cz>');
$dictionary->setHeader('X-Poedit-Language','Czech');
$dictionary->setHeader('X-Poedit-Country','Czech Republic');

// Set simple untranslated string for translator team
$dictionary->addOriginal('Translate this please');

// Set simple translation without plurals
$dictionary->addOriginal('Translation team')->setTranslation('Překladatelský team');

// Set translation with plurals (most complicated way)
$dictionary->addOriginal('%s monkey')->setPlural('%s monkeys')->setTranslation('%s opice',0)->setTranslation('%s opičky',1)->setTranslation('%s opiček',2);

// Set Translation with plurals easier
$dictionary->addOriginal(array('%s dog','%s dogs'))->setTranslations(array('%s pes','%s psi','%s psů'));

// Set same translation with another context
// Many apps have problems with context or multiple same untranslated strings
$dictionary->addOriginal('New','New man')->setTranslation('Nový');
$dictionary->addOriginal('New','New woman')->setTranslation('Nová');

// Easiest way to define translation
$dictionary->addOriginal('Cat','',NULL,'Kočka'); //simple
$dictionary->addOriginal('Cat','Beautifull woman',NULL,'Kočička'); // another context
$dictionary->addOriginal(array('%s cat','%s cats'),'',NULL,array('%s kočka','%s kočky','%s koček')); // with plurals

// There is also support for adding many types of comments
$dictionary->getOriginal('Translate this please')->setComment('comment','translator-comments');
$dictionary->getOriginal('Translate this please')->setComment('extracted-comment','extracted-comments');
$dictionary->getOriginal('Translate this please')->setComment('reference','reference...');
$dictionary->getOriginal('Translate this please')->setComment('flag','flag...');
$dictionary->getOriginal('Translate this please')->setComment('previous-context','previous-context');
$dictionary->getOriginal('Translate this please')->setComment('previous-untranslated-string','previous-untranslated-string');

// Comments can be set by array
$dictionary->getOriginal('Translate this please')->setComments(
	array(
		'comment'                      => 'translator-comments',
		'extracted-comment'            => 'extracted-comments',
		'reference'                    => 'reference...',
		'flag'                         => 'flag...',
		'previous-context'             => 'previous-context',
		'previous-untranslated-string' => 'previous-untranslated-string',
	)
);

// Save dictionary
$dictionary->saveDictionary('./dictionary.po');
$dictionary->saveDictionary('./dictionary.mo');

// Optional show content of dictionary
printf("<h2>Files:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->files,true)));
printf("<h2>Headers:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->getHeaders(),true)));
printf("<h2>Translations:</h2><pre>%s</pre>",htmlspecialchars(print_r($dictionary->getTranslations(),true)));

6) Discussion

When you need to discuss, write in Nette forum in czech language or on Google+ in english language.

About

Just another one NetteTranslator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages