laravel 有条件的本地化

laravel localization with conditions

我们能否为 transLang 方法提供除复数之外的条件,因此它会检查语言环境和条件以提供需要翻译

For Example: We have some translations in English for Organisation 1. And different translations in English for Organisation 2. Now according to user login for organisation, the translations should be shown. Remember the locale is same.

我认为你不应该对组织名称使用翻译,而是创建一个直接输出的变量。但是,您可以将 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 ])

所以重温一下:"amount" 现在只是一个代表组织的数字,就像枚举一样。

为什么不选择这样的东西:

@lang("organistation.$organisationId.text")

并在 resources/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!'
    ]
];

等等