intelligenia / behistun

PHP应用的简单翻译管理器

v0.1.3 2017-04-20 10:56 UTC

This package is not auto-updated.

Last update: 2024-09-20 20:51:51 UTC


README

Behistun是一个简单的PHP翻译管理器

要求

PHP 5.4及通过 composer 安装的依赖项(AdoDBTwig模板系统)。

安装

从Packagist安装,输入以下命令

composer install

配置

定义可用语言

// For example we are going to translate to Spanish and French
$LANGUAGES = ["es_ES", "fr_FR"];

从behistun包中加载init.php文件

在您的index.php或init.php文件中加载init.php文件。

require_once __DIR__ . '/vendor/intelligenia/behistun/behistun/init.php';

使用

模板

此包依赖于Twig模板系统,因此您必须使用以下Twig标签来标记可翻译的文本块

{% translatable '<id>' %}
This text will be translated
{% endtranslatable %}

该ID将用于在处理翻译时识别可翻译文本块。您应该将其设置为有助于您轻松识别所表示的块的值。

编译模板中的所有源文本

运行此PHP脚本,它将获取所有源文本,并在与模板相同的目录中创建一个 locales/LANGUAGE_CODE/LC_MESSAGES/ 目录

php vendor/intelligenia/behistun/behistun/bin/update_translations.php <template-path> <language> [purge]

例如

php vendor/intelligenia/behistun/behistun/bin/update_translations.php ~/projects/my-web/public_html/templates/ en_US

翻译

locales/LANGUAGE_CODE/LC_MESSAGES/ 目录包含两个文件

web.source.php

可翻译ID与源文本之间的原始关联。

web.translation.php

每个翻译的位置。请记住,每个翻译都通过您在可翻译标签中使用的ID来识别。

更改语言

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

许可证

MIT许可证.

作者