php - Laravel 本地化字符串中的参数

标签 php laravel

我希望在 lang/en/mymsgs.php

中有这样的内容
'string1' => 'Welcome %1, Please meet %2'

从我的代码中获取“string1”时,我会提供 %1 和 %2 的内容。

我找不到执行此操作的方法。任何指针?

最佳答案

Laravel 消息本地化使用命名参数,而不是数字参数。

重写您的示例消息:

'string1' => 'Welcome :user, Please meet :other',

您现在可以使用,例如:

trans('string1', [ 'user' => 'Ainsley', 'other' => 'Hayden' ]);

关于php - Laravel 本地化字符串中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30242119/

相关文章:

php - Zend 框架 : Proper way to interact with database?

php - 从字符串中删除变音符号

laravel - 配置 Apache 反向代理以在生产环境中托管 Laravel Echo Server

php - 外键约束的格式不正确 - Laravel

php - Laravel 上传到 cpanel css 问题

javascript - Magento 文本字段最大字段长度(5 个字符)

php - 什么是 'module_number' 作为 zend_register_list_destructors_ex 的参数

php - 发布带有值的动态复选框 ID

php - WhereHas()/orWhereHas 未按预期约束查询

php - 在 laravel 约会前一小时发送通知