wedesignit/laravel-translations-import 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

wedesignit/laravel-translations-import

Composer 安装命令:

composer require wedesignit/laravel-translations-import

包简介

Import translations from your Laravel translation files to your database.

README 文档

README

This package provides you with commands to deal with your lang files and your database. Instead of manually adding translations to your database, this commandset gives you the tools needed to import and export translations, find unimported translations in your php/twig files, clean empty translations from your database and to delete all translations in one go!

Usefulness and credit

It's particularly useful in the case you're using a package like
Spatie's Laravel Translation Loader. In this case the lang files can be used as 'defaults' to import into a project. When you want to add new defaults, just add them to your lang file(s), rerun the import command and the newly added translations will be added for usage, without the existing translations being modified. You can export the files if you want the updated translations to be used as default.

Credit to Barryvdh's Translation Manager for creating this package which we could build on.

Upgrading

See upgrading for details.

Usage

The import command

php artisan translations:import

This command will import all translation files located in the set lang folder.

The command offers 6 options:

  • ignore-locales: Allows you to set locales that should not be imported.
    Example: --ignore-locales=fr,de.
  • ignore-groups: Allows you to set groups that should not be imported.
    Example: --ignore-groups=routes,admin/dashboard,frontend/employer.
  • only-groups: Allows you to set groups that should only be imported. No other group will be imported. Works like ignore-groups.
  • overwrite: Option to enable overwriting existing translations in the database. Shortcut o.
  • allow-vendor: Option to allow vendor translation overrides to be imported (The lang files at lang/vendor/{package}/). Shortcut a.
  • allow-json: Option to allow JSON translations to be imported. Shortcut j.

Command options should be split by commas.
For groups, a wildcard (*) can be used at the end to allow all subdirectories to be processed as well (for either ignore or only). Example: --only-groups=admin/*.

The export command

php artisan translations:export

This command will take all translations in the database, and write them to the lang folder. Existing translations will be overwritten (except for files that don't exist in the database).

The command offers 4 options:

  • ignore-groups
  • only-groups
  • allow-vendor
  • allow-json

These options work the same as explained with the import command

The find command

php artisan translations:find

This command will find all translations in your php/twig files, and import them if they do not exist in the database.

Keep in mind that this command should be handled with care, imagine we have this in a blade and trans file:

@foreach(__('admin/employers.datatables.filter.statuses') as $value => $translation)
    <option value="{{$value}}">{{$translation}}</option>
@endforeach
// admin/employers.php
'datatables' => [
    'filter' => [
        'statuses' => [
            'active' => 'Actief',
            'not-active' => 'Inactief',
            'approved' => 'Goedgekeurd',
            'declined' => 'Afgekeurd',
        ],
    ],
];

The command will find this translation and import it, it will encode the value of the 'statuses'.

The command offers 1 option:

  • path: By default, the find command starts in the root directory. Using this option, you can point the command to only search in a subdirectory.
    Example: --path=resources/lang.
  • force-confirm: Option to enable automatically confirming all found translations. Without this, you have to confirm each import manually. Shortcut c.

The clean command

php artisan translations:clean

This command will remove all translations which do not have a stored value.

The command has no options.

The delete command

php artisan translations:nuke

This command will remove all translations.

The command has 1 option:

  • only-groups

This options works the same as explained with the import command

Installation

You can install the package via composer:

composer require wedesignit/laravel-translations-import

Config

By default, the config sets the tables and columns following the language_lines table from the Spatie's Laravel Translation Loader migration, with the following structure:

  • group: Stores the group (string).
  • key: Stores the key (string).
  • text: Stores the translation (in JSON format) (text).

Optionally you could publish the config file to change table and column names.

php artisan vendor:publish --provider="WeDesignIt\LaravelTranslationsImport\TranslationsImportServiceProvider" --tag="config"

This is the content of the published config file:

<?php

return [
    /**
     * The table where the translations are stored
     */
    'table' => 'language_lines',

    /**
     * The column where the translations group should be stored
     */
    'group' => 'group',

    /**
     * The column where the translation key should be stored
     */
    'key' => 'key',

    /**
     * The column where the translation text itself should be stored
     */
    'translations' => 'text',

    /**
     * Array of functions which are used to get translations
     */
    'trans_functions' => [
        'trans',
        'trans_choice',
        'Lang::get',
        'Lang::choice',
        'Lang::trans',
        'Lang::transChoice',
        '@lang',
        '@choice',
        '__',
        '$trans.get',
    ],
];

wedesignit/laravel-translations-import 适用场景与选型建议

wedesignit/laravel-translations-import 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.01k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 06 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「import」 「translations」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 19.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 14
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-06-07