Search code examples
laravellaravel-localization

laravel localization with conditions


Can we provide conditions to trans or Lang method other than pluralization ones, so it checks locale & the condition both to provide the required translations

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.


Solution

  • Why not go with something like that:

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

    And in 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!'
        ]
    ];
    

    etc.