hongyukeji/laravel-translate

Package description here.

v1.3.5 2020-05-07 13:45 UTC

This package is auto-updated.

Last update: 2024-11-08 00:24:22 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

全网首款支持所有语言翻译插件,自由扩展,无缝对接。

采用鸿宇科技专利《宏观设计模式》开发。

更多请点击 https://www.hongyuvip.com

特点

  • 支持全网络翻译服务商
  • 支持自由扩展且易维护

支持

  • 百度翻译
  • 有道翻译
  • 上述语言翻译服务商比较常用,其他短信如有需要可联系Shadow集成
  • 如需支持其他语言服务商,可以自行Fork,在src/Sms.php中添加对应的语言发送方法即可
  • 语言快速集成(参考《宏观设计模式》 — 鸿宇科技出品)

Installation

This package can be used in Laravel 5.6 or higher and needs PHP 7.2 or higher.

You can install the package via composer:

composer require hongyukeji/laravel-translate

composer require --dev hongyukeji/laravel-translate dev-master

Config

After installation publish the config file:

php artisan vendor:publish --provider="Hongyukeji\LaravelTranslate\TranslateServiceProvider"

You can specify your source language, the target language(s), the translator and the path to your language files in there.

Translators

If you have lots of translations to make I recommend Deepl. It is fast, reliable and you will not encounter any rate limiting.

Usage

Missing translations

Simply call the artisan missing command for translating all the translations that are set in your source language, but not in your target language:

php artisan translate:missing

E.g. you have English set as your source language. The source language has translations in auth.php:

<?php

return [
    'failed' => 'These credentials do not match our records.',
    'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
];

Your target language is German. The auth.php file has the following translations:

<?php

return [
    'failed' => 'Diese Kombination aus Zugangsdaten wurde nicht in unserer Datenbank gefunden.',
];

The artisan missing command will then translate the missing auth.throttle key.

All translations

To overwrite all your existing target language keys with the translation of the source language simply call:

php artisan translate:all

This will overwrite every single key with a translation of the equivalent source language key.

Parameters

Sometimes you have translations like these:

'welcome' => 'Welcome, :name',

They can be replaced with variables. When we pass these placeholders to a translator service, weird things can happen. Sometimes the placeholder comes back in upper-case letters or it has been translated. Thankfully the package will respect your variable placeholders, so they will be the same after the translation.

Extending

You can create your own translator by creating a class that implements \Ben182\AutoTranslate\Translators\TranslatorInterface. Simply reference it in your config file.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email moin@benjaminbortels.de instead of using the issue tracker.

Credits

License

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

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.