almacil/php-translate
最新稳定版本:1.1.0
Composer 安装命令:
composer require almacil/php-translate
包简介
README 文档
README
🈳 Almacil PHP Translate
This is a library written in PHP to internationalize websites and apps made with PHP.
Features
- Translate from json files
- Translate words or phrases on the fly with Google Translate and store to json files
Installation
Installation is possible using Composer
composer require almacil/php-translate
Usage
Create an instance of \Almacil\Translate:
// Require composer autoloader require __DIR__ . '/vendor/autoload.php'; // Language to translate from auto detectable language $lang = 'en'; // Directory containing the json files with the translations $directory = __DIR__ . '/i18n'; // We want the library to search for the translations that it cannot find in the files and to include the translations in the files $findMissingTranslations = true; // Create de instance $translate = new \Almacil\Translate($lang, $directory, $findMissingTranslations); echo $translate->get('Hola mundo!'); // Hello world!
Create a function with a short name for ease:
// ... after the setup function t($text, $params = null) { global $translate; return $translate->get($text, $params); } echo '<p>' . t('Hola mundo!') . '</p>'; // <p>Hello World!</p>
Params
We can include parameters in translations like this:
// ./i18n/en.json { "hola-name": "Hello {{name}}!" }
// Some PHP file echo '<p>' . t('hola-name', array('name' => 'Rubén')) . '</p>'; // <p>Hello Rubén!</p>
Made with ❤️ by developer for developers
统计信息
- 总下载量: 852
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-08-06