hpolthof/laravel-translations-db
Composer 安装命令:
composer require hpolthof/laravel-translations-db
包简介
A database translations implementation for Laravel 5.
README 文档
README
This package was created, as an in-place replacement for the default TranslationServiceProvider and mend for everyone who got tired of collecting translations in language files and maintaining dozens of arrays, filled with lots and lots of keys. Keys will be added to the database automatically, so no more hussling with adding your keys to the translations file, automatic translation with Google Translate is also supported. You'll never forget to translate a key anymore! In production your keys will be cached to ensure the localization stays blazing fast!
Installation
Require this package with composer:
composer require hpolthof/laravel-translations-db
Like to live on the edge? Use:
composer require 'hpolthof/laravel-translations-db:*@dev'
After updating composer, we'll have to replace the TranslationServiceProvider the our ServiceProvider in config/app.php.
Find:
'Illuminate\Translation\TranslationServiceProvider',
and Replace this with:
'Hpolthof\Translation\ServiceProvider',
The ServiceProvider will now be loaded. To use this package properly you'll also need the create a table in your database, this can be achieved by publishing the config and migration of this package.
Run the following command:
php artisan vendor:publish --provider='Hpolthof\Translation\ServiceProvider'
and afterwards run your migrations:
php artisan migrate
And that's all there is to it!
Usage
You can just start using translations as you would normaly do with the Laravels default package. The functions trans() and Lang::get() can be used as you normaly would.
For more information about Localization and the usage of these functions, please refer to the Documentation on the mather.
Files are still possible
The usage of translation files is however still possible. Every translation prefixed by a namespace is parsed through the old TranslationServiceProvider. This is needed for external packages that come with there own translation files. But in general you shouldn't be bothered by this.
Web interface
To prevent you from having to access the database for every translation, a web interface is available to manager your translations.
Direct your browser to:
http://{projectUrl}/_translations
This location can also be changed in the
translation-db.phpconfig file.
Configure your workset
At the Translations Manager you'll have to select a certain group, as well as a locale. The first locale you'll select represents the language you'll be using as a reference to create your translations. In the textfield you should enter the locale you want to create or edit.
The locale you should enter in the textfield, can be any locale. There is no need to predefine anything. The entries will be created just as you submit your translations. After selecting these settings, just hit the Load button and all the collected translations will be listed.
Editing
After your translation keys are loaded, a textbox will appear on each row. You can just type in your translation, when the textbox loses it's focus, the translation will be saved.
The saving takes place through some Ajax calls. If you are using the Laravel Debugbar it will be advised to disable the Debugbar as every Ajax request slows your browser down. By default de Debugbar will therefor be disabled, it the Debugbar is used. If you want to leave the Debugbar on, you can just enable it within the
translation-db.phpconfig file.
Google Translate integration
As of version 0.4.0 support integration with Google Translate is included. In the Translations Manager a button has been added for Google Translate. All blank and currently opened translations will then be processed through Google Translate and be written into the textbox.
These translations are not yet stored into the database and need to be reviewed manually. As soon as the textbox loses it's focus the translation will be stored. To prevent you from being blocked by Google there is an interval of 500 miliseconds between each request.
Turn it off
If you don't want any additional routes forced into your application, you can disable the whole web interface by
changing the translation-db.webinterface config from TRUE to FALSE.
Importing and exporting
To ease the proces of migrating to translations in the database, two commands are available since version 0.3.
Import
To import all translations out of your current language files, you can use the command:
php artisan translation:fetch
This will import all available translations in language files into the database.
To import just some specifics you can also make use of the options
--localeand--group.
Export
To dump the translations from your database back to your filesystem, use:
php artisan translation:dump
The options
--localeand--groupare also available for this command. Caution: all current files will be overwritten, so use with care!
hpolthof/laravel-translations-db 适用场景与选型建议
hpolthof/laravel-translations-db 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.77k 次下载、GitHub Stars 达 52, 最近一次更新时间为 2015 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「translation」 「laravel」 「localization」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hpolthof/laravel-translations-db 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hpolthof/laravel-translations-db 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hpolthof/laravel-translations-db 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A custom URL rule class for Yii 2 which allows to create translated URL rules
A Laravel Eloquent model trait for translatable resource
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 5.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 54
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL2
- 更新时间: 2015-06-10
