Skip to content

Unused param $domain in translation helpers/methods #9584

Closed
@kamui545

Description

@kamui545

Hey guys,

The $domain param in the following functions/methods is not used:

Illuminate/Foundation/helpers.php

Illuminate/Translation/Translator.php

As per the doc, domains are declared in the key name like this trans('domain.message_key')

In Translator@trans() we can clearly see this param is not used

public function trans($id, array $parameters = [], $domain = 'messages', $locale = null)
{
    return $this->get($id, $parameters, $locale);
}

Now, the thing is, this param is needed in the Translator class because it implements the Symfony\Component\Translation\TranslatorInterface.

Maybe we could at least modify the trans() and trans_choice() helpers like this:

function trans($id = null, $parameters = [], $locale = null)
{
    if (is_null($id)) {
        return app('translator');
    }

    return app('translator')->trans($id, $parameters, null, $locale);
}

function trans_choice($id, $number, array $parameters = [], $locale = null)
{
    return app('translator')->transChoice($id, $number, $parameters, $locale);
}

but it would still be confusing for people dealing with the translator class directly.

Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions