定制 mortendhansen/laravel-database-translations 二次开发

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

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

mortendhansen/laravel-database-translations

Composer 安装命令:

composer require mortendhansen/laravel-database-translations

包简介

Managing laravel translations in database

README 文档

README

run-tests

Laravel translations managed in database

enables Laravels translations to be overridden, added or edited in database.

Laravel ships with localization built around a file structure that can be used in two ways:

  • a .json file per language in the /lang directory, or
  • php files returning an array nested in folders where first level is the locale

As a developer, it can be cumbersome to keep multiple language files updated with the keys - and sometimes your stakeholders / customers or user may want to participate in translating the software.

This package will front laravels localization so that

  • translation/localization can happen in database
  • missing keys are created on the fly, so you don't have to worry about missing keys in certain locales
  • if a value is not set in the database, or a key is missing, it falls back to laravels defaults

Eg, you may use a translation like this:

__('animal') 

The key will be created in the table for the current locale. So, if you have visitors from 10 different countries, it will update the table whenever the key is encountered and found missing.

If you have an en.json that sets {"animal":"bird"}, the result of the above will be 'bird'. You may now override that in the database by simply updating the record with:

$record = DatabaseLangItem::where('locale', 'en')->where('group', '*')->where('key', 'animal')->first();
$record->value = 'giraffe';
$record->save();

now result of __('animal') is giraffe.

Installation

composer require mortendhansen/laravel-database-translations

Publish the migration:

artisan vendor:publish --provider="MortenDHansen\LaravelDatabaseTranslations\DatabaseTranslationsServiceProvider" --tag="migrations"
artisan migrate

Now you need to replace the laravel TranslationServiceProvider with the service provider from the package

\MortenDHansen\LaravelDatabaseTranslations\DatabaseTranslationsServiceProvider::class,
// Illuminate\Translation\TranslationServiceProvider::class, 

Caching

Of course getting, and writing language keys whenever they appear is quite a heavy load of you have many of them. Therefore the package caches the keys. When cache is cold, the pages may be quite slow. You can use the artisan command dbtrans:cache-rebuild to drop keys and rebuild from table.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固