Laravelで多言語化用に__ヘルパー関数使って、"resources/lang/"以下にjsonファイルを作ることが多々あります。
毎回、そのjsonファイルを作るのが面倒だったので、ヘルパー関数を調べてjsonファイルを作ってくれるライブラリがないか探したところありました。
こちらです。
kkomelin/laravel-translatable-string-exporter
利用方法
至極簡単です。
対象プロジェクト直下でcomposerで導入。
生成したい言語名を引数にコマンド実行で生成してくれます。
1. インストール
composer require kkomelin/laravel-translatable-string-exporter
2.生成
php artisan translatable:export <lang>
php artisan translatable:export es
php artisan translatable:export es,bg,de
生成されるファイル
php artisan make:auth
&php artisan migrate
後に自動生成した言語ファイルです。
{
"Login": "Login",
"E-Mail Address": "E-Mail Address",
"Password": "Password",
"Remember Me": "Remember Me",
"Forgot Your Password?": "Forgot Your Password?",
"Reset Password": "Reset Password",
"Send Password Reset Link": "Send Password Reset Link",
"Confirm Password": "Confirm Password",
"Register": "Register",
"Name": "Name",
"Verify Your Email Address": "Verify Your Email Address",
"A fresh verification link has been sent to your email address.": "A fresh verification link has been sent to your email address.",
"Before proceeding, please check your email for a verification link.": "Before proceeding, please check your email for a verification link.",
"If you did not receive the email": "If you did not receive the email",
"click here to request another": "click here to request another",
"Toggle navigation": "Toggle navigation",
"Logout": "Logout"
}
実行環境
root@cd7df3ed8fc8:/var/www # php artisan -V
Laravel Framework 5.7.15
root@cd7df3ed8fc8:/var/www # php -v
PHP 7.2.4-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Apr 5 2018 08:53:57) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.4-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies