intelligenia / behistun
A simple translation manager for your PHP application
Requires
- php: >=5.4.0
- twig/twig: 1.32
This package is not auto-updated.
Last update: 2024-11-29 21:38:18 UTC
README
Behistun is a simple PHP translation manager
Requirements
PHP 5.4 and dependencies installed by composer (AdoDB and Twig template system).
Installation
Install from packagist typing:
composer install
Configuration
Define the available languages
// For example we are going to translate to Spanish and French $LANGUAGES = ["es_ES", "fr_FR"];
Load the file init.php file from the behistun package
Load the init.php file in your index.php or init.php file.
require_once __DIR__ . '/vendor/intelligenia/behistun/behistun/init.php';
Use
Templates
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.
Compile all source texts from templates
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
Translation
This locales/LANGUAGE_CODE/LC_MESSAGES/ directory contains two files:
web.source.php
Original association between translatable ids and source texts.
web.translation.php
Where each translation goes. Remember that each translation is identified by the id you used in the translatable tag.
Changing language
// 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);
License
Authors
- First prototype made by Diego J. Romero López at intelligenia (diegoREMOVETHIS@REMOVETHISintelligenia.com)