Laravel 5使用@lang助手提供翻译
<!-- file: template.blade.php -->
@lang('some text')Laravel 5还可以根据变量将字符串复数。
// file: controller.php
echo trans_choice('messages.apples', 10);然后,翻译文件将包含以下行来翻译苹果:
// file: /resources/lang/en
'apples' => 'There is one apple|There are many apples',现在,我想在刀片模板中使用复数,但我不知道如何使用它。我尝试了以下几种方法:
<!-- file: template.blade.php -->
Course duration: {{ $course.days }} @lang('day|days', $course.days)这似乎是我的逻辑语法,但这只给了我一个关于输入参数2需要是一个数组的错误。我还尝试了这个:
<!-- file: template.blade.php -->
Course duration: {{ $course.days }} @lang('day|days', [$course.days])还有这个:
<!-- file: template.blade.php -->
Course duration: {{ $course.days }} @lang(['day|days', $course.days])发布于 2018-09-03 18:23:15
有一个@choice刀片指令可以做到这一点。
Course duration: {{ $course->days }} @choice('day|days', $course->days)发布于 2018-09-03 18:23:23
您必须在您的某个转换文件中注册一个新的键控条目,比如plurals.php。那么正确的方法应该是:
//in plurals.php
//...
'day' => 'day|days',
//...然后,您可以像这样检索条目
{{trans_choice('plurals.day', $course->days)}} //assuming the arrow syntax is how you retrieve a property in php :P发布于 2021-07-21 15:26:45
可以将它与如下所示的变量一起使用
//plurals.php
'day' => 'one day| :n days',您可以在刀片文件中执行此操作:
{{ trans_choice('plurals.day', $course->days), ['n' => $course->days] }} 您甚至可以使用以下代码
{{ trans_choice('plurals.like', $post->likes), ['n' => $post->likes] }} 'like' => '{0} Nobody likes this|[1,19] :n users like this|[20,*] Many users like this'https://stackoverflow.com/questions/52147715
复制相似问题