定制 lematosdefuk/localizator 二次开发

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

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

lematosdefuk/localizator

最新稳定版本:v0.7.1-alpha

Composer 安装命令:

composer require lematosdefuk/localizator

包简介

Localizator is a small tool for Laravel that gives you the ability to extract untranslated strings from project files. It works using the artisan command line and the provided localize command.

README 文档

README

Latest Version on Packagist Total Downloads GitHub Tests Action Status GitHub Code Style Action Status

Localizator is a small tool for Laravel that gives you the ability to extract untranslated string from your project files with one command.

Sponsors

locale_ad

Support

Buy Me A Coffee

DigitalOcean Referral Badge

Compatibility

Laravel Localizator
6.x LTS ^0.3
8.x *
9.x ^0.8

Installation

You can install the package via composer:

composer require --dev amirami/localizator

This package makes use of Laravels package auto-discovery mechanism, which means if you don't install dev dependencies in production, it also won't be loaded.

If for some reason you want manually control this:

  • add the package to the extra.laravel.dont-discover key in composer.json, e.g.
    "extra": {
      "laravel": {
        "dont-discover": [
          "amirami/localizator"
        ]
      }
    }
  • Add the following class to the providers array in config/app.php:
    Amirami\Localizator\ServiceProvider::class,
    If you want to manually load it only in non-production environments, instead you can add this to your AppServiceProvider with the register() method:
    public function register()
    {
        if ($this->app->isLocal()) {
            $this->app->register(\Amirami\Localizator\ServiceProvider::class);
        }
        // ...
    }

Note: Avoid caching the configuration in your development environment, it may cause issues after installing this package; respectively clear the cache beforehand via php artisan cache:clear if you encounter problems when running the commands

You can publish the config file with:

php artisan vendor:publish --provider="Amirami\Localizator\ServiceProvider" --tag="config"

This is the contents of the published config file:

<?php

return [

    /**
     * Localize types of translation strings.
     */
    'localize' => [
        /**
         * Short keys. This is the default for Laravel.
         * They are stored in PHP files inside folders name by their locale code.
         * Laravel comes with default: auth.php, pagination.php, passwords.php and validation.php
         */
        'default' => true,

        /**
         * Translations strings as key.
         * They are stored in JSON file for each locale.
         */
        'json'    => true,
    ],

    /**
     * Search criteria for files.
     */
    'search'   => [
        /**
         * Directories which should be looked inside.
         */
        'dirs'      => ['resources/views'],
        
        /**
         * Subdirectories which will be excluded.
         * The values must be relative to the included directory paths.
         */
        'exclude' => [
            //
        ],

        /**
         * Patterns by which files should be queried.
         * The values can be a regular expression, glob, or just a string.
         */
        'patterns'  => ['*.php'],

        /**
         * Functions that the strings will be extracted from.
         * Add here any custom defined functions.
         * NOTE: The translation string should always be the first argument.
         */
        'functions' => ['__', 'trans', '@lang']
    ],

    /**
     * Should the localize command sort extracted strings alphabetically?
     */
    'sort'     => true,

];

Usage

To extract all the strings, it's as simple as running:

php artisan localize de,fr

This command will create (if don't exist) de.json and fr.json files inside the resources/lang directory. If you have short keys enabled and used in your files (e.g. pagination.next) the localize command will create folders de and fr inside resources/lang directory and PHP files inside by the short key's prefix (e.g. pagination.php).

You can also run the artisan command without the country code arguments.

php artisan localize

In this case translation strings will be generated for the language specified in app.locale config.

Note: Strings you have already translated will not be overwritten.

Remove Missing Keys

By default, the strings inside the locale files will be preserved even if they are not present the next time you run the localize command. If you want to remove those keys that are not present in your files anymore you can append the --remove-missing option to the localize command.

php artisan localize --remove-missing

Key Sorting

By default, the strings generated inside those JSON files will be sorted alphabetically by their keys. If you wanna turn off this feature just set sort => false in the config file.

Searching

The way the strings are being extracted is simple.

We are looking inside the directories defined in search.dirs config, we match the files using patterns defined in search.patterns, and finally we look to extract strings which are the first argument of the functions defined in search.functions.

You are free to change any of these values inside the config file to suit you own needs.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

lematosdefuk/localizator 适用场景与选型建议

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

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

围绕 lematosdefuk/localizator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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