masteryuri / laravel-edit-trans
管理 Laravel 翻译
Requires
- php: ~5.5|~7.0
- illuminate/support: ~5.1
- intervention/image: 2.*
Requires (Dev)
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
This package is not auto-updated.
Last update: 2024-09-20 19:19:49 UTC
README
这是一个用于管理基于 Laravel 5 项目本地化文件的组件,支持丰富的编辑器。
安装
通过 Composer
$ composer require masteryuri/laravel-edittrans
将服务提供者添加到 /config/app.php
'MasterYuri\EditTrans\ServiceProvider',
发布配置和公共资源
php artisan vendor:publish --provider="MasterYuri\EditTrans\ServiceProvider"
用法
管理页面链接是
'/admin/edit_trans' // In case if config('admin-edit-trans.route.prefix') is equal to 'admin'
或操作
'MasterYuri\EditTrans\Controller@pageList'
配置
配置文件是 'admin-edit-trans.php'。其中包含描述所有参数的注释。
Artisan 工具
库包含一个工具,允许您将字符串从视图移动到本地化文件。在大多数简单情况下,您只需将字符串包装在特殊标签中
<h1>{{--@@--}}Some title{{--@@--}}</h1>
并运行命令
php artisan viewstolocales:run
它将文本替换为
<h1>@lang('home.some_title')</h1>
并为所有现有区域创建新的本地化文件(或追加到现有文件)。
选项
使用 onlylocale 选项,您可以使其只为一个区域生成
php artisan viewstolocales:run --onlylocale=en
在标签中包装标签时,您可以声明变量名称和保存路径。例如
我们在 /resources/views/site/home.blade.php 有一个视图和一条字符串要移动到本地化文件中(视图中的本地路径是 '/site/home.blade.php')。让我们运行 php artisan viewstolocales:run --onlylocale=en 看看会得到什么
示例 1
保存原始子目录和文件名,根据变量文本生成变量名。
视图中的源字符串
<h1>{{--@@--}}Some title{{--@@--}}</h1>
视图中的最终字符串
<h1>@lang('site/home.some_title')</h1>
本地化文件路径
/resources/lang/en/site/home.php
本地化内容的最终形式
return ["some_title" => "Some title"]
示例 2
保存原始子目录和文件名,使用自定义变量名。
视图中的源字符串
<h1>{{--@the_title@--}}Some title{{--@@--}}</h1>
视图中的最终字符串
<h1>@lang('site/home.the_title')</h1>
本地化文件路径
/resources/lang/en/site/home.php
本地化内容的最终形式
["the_title" => "Some title"]
示例 3
相同的情况。
视图中的源字符串
<h1>{{--@.the_title@--}}Some title{{--@@--}}</h1>
视图中的最终字符串
<h1>@lang('site/home.the_title')</h1>
本地化文件路径
/resources/lang/en/site/home.php
本地化内容的最终形式
["the_title" => "Some title"]
示例 4
保存原始子目录和文件名,使用自定义多级变量名。
视图中的源字符串
<h1>{{--@.the_title.inner1.inner2@--}}Some title{{--@@--}}</h1>
视图中的最终字符串
<h1>@lang('site/home.the_title.inner1.inner2')</h1>
本地化文件路径
/resources/lang/en/site/home.php
本地化内容的最终形式
["the_title" => ["inner1" => ["inner2" => ["Some title"]]]]
示例 5
将本地化文件放入根目录,保存原始文件名,设置自定义变量名。
视图中的源字符串
<h1>{{--@/.the_title@--}}Some title{{--@@--}}</h1>
视图中的最终字符串
<h1>@lang('home.the_title')</h1>
本地化文件路径
/resources/lang/en/home.php
本地化内容的最终形式
["the_title" => "Some title"]
示例 6
保存原始子目录,设置自定义文件名和自定义变量名。
视图中的源字符串
<h1>{{--@default.the_title@--}}Some title{{--@@--}}</h1>
视图中的最终字符串
<h1>@lang('site/default.the_title')</h1>
本地化文件路径
/resources/lang/en/site/default.php
本地化内容的最终形式
["the_title" => "Some title"]
示例 7
将本地化文件放入根目录,设置自定义文件名和自定义变量名。
视图中的源字符串
<h1>{{--@/default.the_title@--}}Some title{{--@@--}}</h1>
视图中的最终字符串
<h1>@lang('site/default.the_title')</h1>
本地化文件路径
/resources/lang/en/site/default.php
本地化内容的最终形式
["the_title" => "Some title"]
示例 8
设置自定义子目录名称,设置自定义文件名和自定义变量名。
视图中的源字符串
<h1>{{--@the_site/default.the_title@--}}Some title{{--@@--}}</h1>
视图中的最终字符串
<h1>@lang('the_site/default.the_title')</h1>
本地化文件路径
/resources/lang/en/the_site/default.php
本地化内容的最终形式
["the_title" => "Some title"]
示例 9
设置自定义深子目录名称,设置自定义文件名和自定义变量名。
视图中的源字符串
<h1>{{--@the_site/the_site_subdir/default.the_title@--}}Some title{{--@@--}}</h1>
视图中的最终字符串
<h1>@lang('the_site/the_site_subdir/default.the_title')</h1>
本地化文件路径
/resources/lang/en/the_site/the_site_subdir/default.php
本地化内容的最终形式
["the_title" => "Some title"]
示例 10
设置自定义深子目录名称,设置自定义文件名和自定义多级变量名。
视图中的源字符串
<h1>{{--@the_site/the_site_subdir/default.the_title.inner1.inner2@--}}Some title{{--@@--}}</h1>
视图中的最终字符串
<h1>@lang('the_site/the_site_subdir/default.the_title.inner1.inner2')</h1>
本地化文件路径
/resources/lang/en/the_site/the_site_subdir/default.php
本地化内容的最终形式
["the_title" => ["inner1" => ["inner2" => ["Some title"]]]]
示例 11
设置自定义深子目录名称,保存原始文件名,设置自定义变量名。
视图中的源字符串
<h1>{{--@the_site/the_site_subdir/.the_title@--}}Some title{{--@@--}}</h1>
视图中的最终字符串
<h1>@lang('the_site/the_site_subdir/home.the_title')</h1>
本地化文件路径
/resources/lang/en/the_site/the_site_subdir/home.php
本地化内容的最终形式
["the_title" => "Some title"]
示例 12
设置自定义深子目录名称,保存原始文件名,设置自定义变量名。
视图中的源字符串
<h1>{{--@the_site/the_site_subdir/.@--}}Some title{{--@@--}}</h1>
视图中的最终字符串
<h1>@lang('the_site/the_site_subdir/home.the_title')</h1>
本地化文件路径
/resources/lang/en/the_site/the_site_subdir/home.php
本地化内容的最终形式
["the_title" => "Some title"]
记住,您还可以将包含 HTML 标签的大段文本包裹起来
{{--@@--}}
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat.
</p>
<p>
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,
totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit,
sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
</p>
{{--@@--}}
许可
MIT 许可证(MIT)。请参阅许可文件以获取更多信息。