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

Parameter $domain is passed to Translator but never used #2249

Closed
wonderfulll opened this Issue Sep 9, 2013 · 7 comments

Comments

Projects
None yet
6 participants
@wonderfulll
Copy link

wonderfulll commented Sep 9, 2013

There are at least 3 places where $domain is passed, but never used afterwards.

src/Illuminate/Support/helpers.php

function trans($id, $parameters = array(), $domain = 'messages', $locale = null)
{
    return app('translator')->trans($id, $parameters, $domain, $locale);
}

framework/src/Illuminate/Translation/Translator.php

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

framework/src/Illuminate/Translation/Translator.php

public function transChoice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null)
{
    return $this->choice($id, $number, $parameters, $locale);
}
@taylorotwell

This comment has been minimized.

Copy link
Member

taylorotwell commented Oct 1, 2013

Yeah this is because we're still implementing Symfony's TranslatorInterface. I will probably discontinue that in 4.1.

@cdarken

This comment has been minimized.

Copy link

cdarken commented Mar 22, 2014

I know this is an old issue, but still.
You should have left that behavior, I don't think that forcing the use of domain prefix followed by a key is very programmer friendly, I want to be able to use the full string when calling trans() and put all translations in messages.php, and using the default $domain parameter load from there.
While Laravel is very nice, the L10n features in the framework are lacking. You should have stayed with Symfony's approach, even in Symfony 1 it was more well rounded than what Laravel offers now.

@barryvdh

This comment has been minimized.

Copy link
Contributor

barryvdh commented Apr 3, 2014

I also think this is a bit strange behaviour.

Isn't the 'group' in the Laravel Translator sort of the same as the 'domain' in the Symfony Translator?

Wouldn't it make more sense to call trans('My String') or trans('Profile', [], 'buttons') instead of trans('messages.mystring') and trans('buttons.profile').
Imho it would improve the Translator if we could:

  • Set a default domain at runtime or per template, so we don't have to use the group prefix everytime.
  • Be able to use the key as fallback text. Now it returns the key, but because is has to have the group also, you can't use it in your views.
@cdarken

This comment has been minimized.

Copy link

cdarken commented Apr 3, 2014

I'm using an workaround, taking advantage of the fact that the functions in helpers.php are wrapped in if (!function_defined()), I've written my helpers like this:

function trans($id, $parameters = array(), $domain = 'messages', $locale = null)
{
  $translated = app('translator')->trans($domain . '.' . $id, $parameters, $domain, $locale);
  return str_replace($domain . '.', '', $translated);
}

function trans_choice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null)
{
  $translated = app('translator')->transChoice($domain . '.' . $id, $number, $parameters, $domain, $locale);
  return str_replace($domain . '.', '', $translated);
}

It's a bit crude, but it works, except when using replacements, which I didn't have time to debug.

@barryvdh

This comment has been minimized.

Copy link
Contributor

barryvdh commented Apr 3, 2014

Well, you could also extend the Translator if you want.

But the Translator could be improved I think.

@lazlo-bonin

This comment has been minimized.

Copy link

lazlo-bonin commented Jun 3, 2015

This is still an issue in 5.0.

@Levsha-cc

This comment has been minimized.

Copy link

Levsha-cc commented Nov 27, 2015

This is still an issue in 5.1. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment