找到你要的答案

Q:Laravel Logic in language files

Q:laravel逻辑在语言文件

I am trying to do the following:

return array(
    ...
    'hello' => 'Sehr geehrte '.($last_name ? ':salutation' . $last_name : 'Damen und Herren').',',
    ...
);

But this doesn't work as it says that $last_name is undefined (it is passed into the file however).

How can I get this to work?

我试图做以下:

return array(
    ...
    'hello' => 'Sehr geehrte '.($last_name ? ':salutation' . $last_name : 'Damen und Herren').',',
    ...
);

但是,这并不工作,它说,last_name美元是未定义的(它被传递到文件然而)。

我怎样才能得到这个工作?

answer1: 回答1:

You can do two language element like following ...

return array(
    ...
    'hello_with_name' => 'Sehr geehrte :salutation :last_name Damen und Herren',
    'hello' => 'Sehr geehrte :salutation Damen und Herren'
    ...
);

You can call the language items as follows ..

{{trans('language_file_name.hello_with_name', array('salutation' => $salutation, 'last_name' => $last_name)}}

{{trans('language_file_name.hello', array('salutation' => $salutation)}}

你可以像下面这样做两个语言元素…

return array(
    ...
    'hello_with_name' => 'Sehr geehrte :salutation :last_name Damen und Herren',
    'hello' => 'Sehr geehrte :salutation Damen und Herren'
    ...
);

您可以调用语言项目如下。

{{trans('language_file_name.hello_with_name', array('salutation' => $salutation, 'last_name' => $last_name)}}

{{trans('language_file_name.hello', array('salutation' => $salutation)}}
php  laravel  localization  laravel-5