Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible [Bug]: Wrong value returned while retrieving lines from language file #43

Closed
olivervogel opened this issue Jan 14, 2013 · 1 comment

Comments

@olivervogel
Copy link

I just noticed that when 'key' and 'value' are the same in language files, the Lang class returns the key instead of the existing value.

Line in Language file (/app/lang/en/test.php):

'rabbit' => 'rabbit'

Retrieving the line:

return Lang::get('test.rabbit');

Result:

'test.rabbit'

As if the language key doesn't exists.

@raftalks
Copy link
Contributor

Yes, it is just how this line of code works https://github.com/laravel/framework/blob/master/src/Illuminate/Translation/Translator.php#L98

public function get($key, $parameters = array(), $locale = null)
    {
        list($namespace, $group, $item) = $this->parseKey($key);

        // Once we call the "load" method, we will receive back the "domain" for the
        // namespace and group. The "domain" is used by the Symfony translator to
        // logically separate related groups of messages, and should be unique.
        $domain = $this->load($group, $namespace, $locale);

        $line = $this->trans->trans($item, $parameters, $domain, $locale);

        return $line == $item ? $key : $line;
    }

I think it will be better to just return the $line without the conditional statement.

For example when simply returning the $line variable:

trans('test.rabbit') when not having the key still returns "rabbit" as default without the key.

I don't find any importance of returning the full $key string if the array key is not available. Instead we can return the $line.

@taylorotwell will know the reason behind that conditional statement.

joelharkes pushed a commit to joelharkes/framework_old that referenced this issue Mar 7, 2019
Setup fractal and an example transformer
gonzalom pushed a commit to Hydrane/tmp-laravel-framework that referenced this issue Oct 12, 2023
Check error_reporting before throwing ErrorException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants