syntaxseed/translator
最新稳定版本:v1.0.0
Composer 安装命令:
composer require syntaxseed/translator
包简介
Translate strings in your application to multiple languages loaded from JSON files.
README 文档
README
Load JSON language files and translate them in your application.
- Licence: MIT
- Version: 1.0.0
- PHP Versions: 7.x, 8.0+, 8.1+, 8.2+
- Author: Sherri Wheeler
- Packagist: https://packagist.org/packages/syntaxseed/translator
Features
- Easy to use, just set language and point to a JSON file.
- Uses the primary language as the lookup key, so strings are understandable in your application.
- Add any number of languages with a language key.
- All the translations for one string are in the same file/place.
- Fails silently - untranslated strings will just output the lookup string.
- Load more than one language file for different parts of your application.
- Short translation function name (
get) for easy typing. - Switch target language when needed.
Install
Via Composer:
composer require syntaxseed/translator
Or add to composer.json:
"require": {
"syntaxseed/translator": "^1.0"
},
Usage
For a more in-depth example, see
examples/directory.
use Syntaxseed\Translator\Translator; require('../src/Translator.php'); // Initialize with base (lookup) language and target language to translate to. $translations = new Translator('en', 'fr'); // Load a JSON file to the default lookup key. $translations->loadLanguageFile(__DIR__.'/lang.json'); echo($translations->get('Hello World'));
Language File JSON Format
{
"Email address" : {
"fr" : "Addresse courriel",
"es" : "Dirección de correo electrónico"
},
"Last name" : {
"fr" : "Nom de famille",
"es" : "Apellido"
},
"Your name" : {
"fr" : "Votre nom",
"es" : "Su nombre"
}
}
Changelog
- v1.0.0 - (2018-10-27) Created. Added to GitHub.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-15