【发布时间】:2018-03-15 12:13:28
【问题描述】:
我们能否为 trans 或 Lang 方法提供除复数以外的条件,以便它检查语言环境和条件以提供所需的翻译
例如:我们为组织 1 提供了一些英文翻译。并且 组织 2 的不同英文翻译。现在根据组织的用户登录,应显示翻译。 记住语言环境是一样的。
【问题讨论】:
-
请提供您需要的示例
标签: laravel laravel-localization
我们能否为 trans 或 Lang 方法提供除复数以外的条件,以便它检查语言环境和条件以提供所需的翻译
例如:我们为组织 1 提供了一些英文翻译。并且 组织 2 的不同英文翻译。现在根据组织的用户登录,应显示翻译。 记住语言环境是一样的。
【问题讨论】:
标签: laravel laravel-localization
为什么不使用类似的东西:
@lang("organistation.$organisationId.text")
在资源/lang/en/organisation.php 中:
<?php
return [
'first_organization_id' => [
'text' => 'This text belongs to first organisation!',
'text2' => 'Other text belongs to first organisation!'
],
'second_organization_id' => [
'text' => 'This text belongs to second organisation!',
'text2' => 'Other text belongs to second organisation!'
]
];
等等
【讨论】:
"organistation.$organisationId.text" 将查找文件organisation.php,然后查找键值为$organisationId 的数组,然后查找键'text'。因此,您可以在$organisationId 下放置任何值并将其用作数组的键。请记住,您需要使用" 而不是' 来替换$organisationId 变量。
我认为您不应该对组织的名称使用翻译,而应创建一个直接输出的变量。但是,您可能会误用 trans_choice 与常量结合使用该数字来更改输出。
abstract class Organisation
{
const Organisation1 = 1;
const Organisation2 = 2;
const Organisation3 = 3;
// etc
}
翻译
// en/organisations.php
'organisation' => '{1} Coca Cola|{2} 1 Pesi|[3, Inf] Unilever :org'
// in your views
trans_choice('organisations.organisation', ['org' => Organisation::Organisation1 ])
所以重新回顾一下:“数量”现在只是一个代表组织的数字,就像 Enum 一样。
【讨论】: