定制 almacil/php-translate 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

almacil/php-translate

最新稳定版本:1.1.0

Composer 安装命令:

composer require almacil/php-translate

包简介

README 文档

README

GitHub last commit GitHub tag (latest by date) Packagist PHP Version Support GitHub

🈳 Almacil PHP Translate

This is a library written in PHP to internationalize websites and apps made with PHP.


Do you want to contribute?
Donate 1€

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>

Do you want to contribute?
Donate 1€

Made with ❤️ by developer for developers

统计信息

  • 总下载量: 852
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-06