Behistun is a simple PHP translation manager
PHP 5.4 and dependencies installed by composer (AdoDB and Twig template system).
Install from packagist typing:
composer install
// For example we are going to translate to Spanish and French
$LANGUAGES = ["es_ES", "fr_FR"];
Load the init.php file in your index.php or init.php file.
require_once __DIR__ . '/vendor/intelligenia/behistun/behistun/init.php';
This package relies on the Twig template system so you will have to use the following Twig tag to mark a block of text as translatable:
{% translatable '<id>' %}
This text will be translated
{% endtranslatable %}
The id will be used to identify the block of translatable text when dealing with translations. You should set it to value that helps you recognize easily the block it represents.
Run this PHP script that will get all the source texts and create a locales/LANGUAGE_CODE/LC_MESSAGES/ directory in the same directory your templates:
php vendor/intelligenia/behistun/behistun/bin/update_translations.php <template-path> <language> [purge]
For example:
php vendor/intelligenia/behistun/behistun/bin/update_translations.php ~/projects/my-web/public_html/templates/ en_US
This locales/LANGUAGE_CODE/LC_MESSAGES/ directory contains two files:
Original association between translatable ids and source texts.
Where each translation goes. Remember that each translation is identified by the id you used in the translatable tag.
// Call Translator class with the language code you want to translate the texts
// this code only should be executed once, when you have a selected language that is
// different from the default language (e.g. English if your web is for English-speaking people)
$translator = new Translator($LANGUAGE);
- First prototype made by Diego J. Romero López at intelligenia ([email protected])