rebelox/languages
Composer 安装命令:
composer require rebelox/languages
包简介
Languages allows you to easily make a multi-language website.
关键字:
README 文档
README
Languages allows you to easily make a multi-language website.
How is it works
When a users opens the website, the API will gets the user's country using the geoip_country_code_by_name function from the GeoIP API.
Then the API searches the configuration files and gets the right language and then by using the user's language the API gets the right message. If the user has a language cookie, the API will ignore the first step and will get the right message using the user's language saved on the cookie.
Installing
Install using composer
{
"require": {
"rebelox/languages": "^1.0"
}
}
You can also visit the releases and download from there.
Configuration
First of all you need to configurate the api, the configuration is easy, you just need to create two files, one will be the languages file, and the other will be the messages file.
Languages File
The languages file should be like this
{
"default": "default_language",
"lang1": "countries",
"lang2": "countries"
}
Where:
- default is the default language you want to your website use by default.
- lang1 and lang2 are the languages you want to define.
- countries is the the list of countries that use that language.
Here's an exemple:
{
"default": "pt",
"pt" : "BR,PT,AO",
"en" : "UK,US,AU"
}
You may want to check this list to see all ISO-3166 country codes.
======
Messages File
The messages' file structures:
{
"message_name":{
"lang1":"Message in the lang1",
"lang2":"Message in the lang2"
}
}
Where
- message_name is the name you want to give to your message, it's also known has the identifier.
- lang1 and lang2 are the languages you defined on the languages file.
- Message (..) lang1 and lang2 are the messages in the respective languages.
Here's an exemple:
{
"hello":{
"pt":"Olá mundo",
"en":"Hello World"
}
}
Basic Usage
<?php require_once('../vendor/autoload.php'); use Language\Language; $language = new Language(array( 'languages_path' => __DIR__ . "/config/languages.json", 'messages_path' => __DIR__ . "/config/messages.json" )); echo $language->get('hello'); //note that the "hello" is the name of the message, a.k.a the identifier.
Dependencies
To use this API you will need the GeoIP extension.
First you will need to install the .dll extension, follow this instructions guide. Then you will need the database, to get the database just click here and then install on your apache/bin folder.
Contributing
You're welcome to contribute to the better of this API, just file the issues under GitHub, or submit a pull request if you would like to contribute directly.
Examples
You can find some examples on the examples' folder, just try it yourself.
Build Tests
For now I don't have build tests available, I'm working on that...
rebelox/languages 适用场景与选型建议
rebelox/languages 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「language」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rebelox/languages 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rebelox/languages 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rebelox/languages 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Easy to use i18n translation PHP class for multi-language websites
Package for convenient work with Laravel's localization features
Store your language lines in the database, yaml or other sources
Set Links with a specific language parameter
Assign a language to a module
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-30