定制 brnysn/laravel-translation 二次开发

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

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

brnysn/laravel-translation

Composer 安装命令:

composer require brnysn/laravel-translation

包简介

A tool for managing all of your Laravel translations

README 文档

README

This package is api supported fork of Joedixon/Laravel-Translation Package

Original Readme.md

Laravel Translation

Translation management for your Laravel application.

Laravel Translation UI

GitHub GitHub

About Laravel Translation

Laravel Translation is a package for Laravel which allows you full control over your translations when using Laravel's localization functionality.

The package allows you to manage your translations using either the native file based translations, but also provides a database driver which is useful in multi-server setups.

It exposes a user interface allowing you to update existing and add new translations to your application.

Below are a full list of features:

  • File and database drivers
  • Database translation loader (automatically load translations from the database when Laravel's translation retrieval methods and the database driver)
  • User interface to add new languages and add and update translations
  • Artisan commands to manage your translations
  • Scan your application for missing translations

Version Compatibility

Laravel Laravel Translation
6.x 1.x
7.x 1.x
8.x 2.x
9.x 2.x

Installation

Install the package via Composer

composer require brnysn/laravel-translation

Publish configuration and assets

php artisan vendor:publish --provider="Brnysn\Translation\TranslationServiceProvider"

The service provider is loaded automatically using package discovery.

Usage

Configuration

The package ships with a configuration file called translation.php which is published to the config directory during installation. Below is an outline of the settings.

driver [file|database]

Choose either file or database. File translations utilise Laravel's native file based translations and includes support for both array based and json based language files.

route_group_config.middleware [string|array]

Apply middleware to the routes which ship with the package. For example, you may which to use the auth middleware to ensure package user interface is only accessible to logged in users.

api_route_group_config.middleware [string|array]

Apply middleware to the api routes which ship with the package. For example, you may which to use the auth:api middleware to ensure package user interface is only accessible to logged in users.

translation_methods [array]

Choose which of Laravel's translation methods to use when searching for missing translation keys.

scan_paths [array]

Choose which paths to use when searching for missing translations. Narrowing the search to specific directories will result in a performance increase when scanning for missing translations.

ui_url [string]

Choose the root URL where the package user interface can be accessed. All routes will be prefixed by this value.

e.g. setting this value to languages will result in URLs such as languages/{language}/translations

api_url [string]

Choose the root URL where the users can access from api. All routes will be prefixed by this value.

e.g. setting this value to api/languages will result in URLs such as api/languages/{language}/translations

database.languages_table

Choose the name of the languages table when using the database driver.

database.translations_table

Choose the name of the translations table when using the database driver.

Drivers

File

Utitlises Laravel's native php array and JSON based language files and exposes a user interface to manage the enclosed translations. Add and update languages and translations using either the user interface or the built-in Artisan commands.

Database

The database driver takes all of the functionality of Laravel's file based language files, but moves the storage to the database, utilising the connection configured for your Laravel application.

It also replaces the translation loader in the container so all of Laravel's translation retrieval methods (__(), trans(), @lang(), etc) will load the relevant strings from the database rather than the files without the need to change any code in your application. It's a like for like swap.

To utilise the database driver, make sure to update the database table names in the configuration file and run the migrations.

Changing Drivers from File (default) to Database

  1. Update the driver to use database in ./config/translation.php.
'driver' => 'database'
  1. Run the migration to add translations and languages tables.
php artisan migrate
  1. Run the following command and folow the prompts to synchronise the translations between drivers.
php artisan translation:sync-translations
  1. A few questions will be prompted which have to be answered. See the screenshot below:

User interface

Navigate to http://your-project.test/languages (update languages to match the translation.ui_url configuration setting) and use the interface to manage your translations.

First, click on the language you wish to edit. On the subsequent page, find the translation you want to edit and click on the pencil icon or on the text and make your edits. As soon as you remove focus from the input, your translation will be saved, indicated by the green check icon.

Artisan Commands

The package ships with a series of Artisan commands which assist with translation management.

translation:add-language

Add a new language to the application.

translation:add-translation-key

Add a new language key for the application.

translation:list-languages

List all of the available languages in the application.

translation:list-missing-translation-keys

List all of the translation keys in the app which don't have a corresponding translation.

translation:sync-translations

Synchronise translations between drivers. This is useful if you have an exisitng application using the native file based language files and wish to move to the database driver. Running this command will take all of the translations from the language files and insert them in to the database.

translation:sync-missing-translation-keys

This command will scan your project (using the paths supplied in the configuration file) and create all of the missing translation keys. This can be run for all languages or a single language.

brnysn/laravel-translation 适用场景与选型建议

brnysn/laravel-translation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 111 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 brnysn/laravel-translation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 brnysn/laravel-translation 我们能提供哪些服务?
定制开发 / 二次开发

基于 brnysn/laravel-translation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-14