定制 inweb/translations-parser 二次开发

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

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

inweb/translations-parser

最新稳定版本:8.0.2

Composer 安装命令:

composer require inweb/translations-parser

包简介

Parse files and pull translatable phrases

README 文档

README

Parse your files and pull translatable phrases.

Requirements

  • PHP >= 7.1

Installation

You can install the package via composer:

composer require inwebcomp/translations-parser

Give access to you ./lang folder

chmod 0777 -R ./resources/lang

Add facade to your config/app.php file

'aliases' => [
    // ...
    'TranslationsParser' => InWeb\TranslationsParser\TranslationsParserFacade::class
],

Configuration

Run to publish translations-parser.php configuration file

php artisan vendor:publish --provider="InWeb\TranslationsParser\TranslationsParserServiceProvider"

There you can change locales and folders that are used by artisan command

// Locales to save phrases
'locales' => [
    'ru',
    'en'
],

// Directories in which phrases are searched
'directories' => [
    base_path('app'),
    resource_path('views'),
    resource_path('js')
],

// Excluded directories or files
'excluded' => [
    base_path('app/Nova')
],

// Where is your folder with translations
'lang_files_directory' => resource_path('lang')

Sometimes you receive your locales list during the application run. You can just overwrite this setting in your code:

\Config::set('translations-parser.locales', [
    'en',
    'fr
]);

Usage

Artisan commands

Parse translations with artisan command

php artisan translations:parse

Force parse translations. Old translations will be removed

php artisan translations:parse --force

Methods

Get phrases from string

TranslationsParser::parse('<div>@lang("Phrase")</div>');
// ['Phrase']

Get phrases from files in directories

TranslationsParser::parse([
    resouce_path('views'),
    resouce_path('js')
]);
// ['Phrase 1', 'Phrase 2', ...]

Can exclude directories or files from list

TranslationsParser::parse([
    resouce_path('views')
], [
    resouce_path('views/layouts') // Exclude 'views/layouts' directory
]);

Get phrases in {locale}.json file

TranslationsParser::getParsed('en');

Save phrases to .json file

TranslationsParser::save('en', [
    'Phrase'
]);

// Or with values
TranslationsParser::save('en', [
    'Phrase' => 'Value'
]);

By default, phrases would not be overwritten It will be overwritten only if there is no phrase in your .json file, or phrase translation is empty

Set last parameter to true to force writing in .json. You will lose old data

TranslationsParser::save('en', [
    'Phrase' => 'Value'
], true);

Save one phrase translation

TranslationsParser::translate('en', 'Phrase', 'Translation');

Testing

composer test

Credits

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-10