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

extract translation misbehaves when locale is provided along with parameters #2574

Open
grossmannmartin opened this issue Mar 2, 2023 · 0 comments

Comments

@grossmannmartin
Copy link
Member

Describe the bug

It is possible to pass locale and translation domain to the t function.

The method header is like

/**
 * @param string $id
 * @param array $parameters
 * @param string|null $domain
 * @param string|null $locale
 * @return string
 */
function t($id, array $parameters = [], $domain = null, $locale = null)

Following calls works fine

t('my string');
t('my %adjective% string', ['%adjective%' => 'awesome']);
t('my string', locale: 'cs');
t('my string, locale: $locale);

However following throws an exception on php phing translations-dump command

t('my %adjective% string', ['%adjective%' => 'awesome'], locale: $locale);
// Can only extract the message ID or message domain from a scalar, concatenated string or "\Shopsys\FrameworkBundle\Component\Translation\Translator" class constant, but got "PhpParser\Node\Expr\Variable".

// third parameter is not actually a translation domain, but named argument (fourth)
t('my %adjective% string', ['%adjective%' => 'awesome'], null, $locale);
// Can only extract the message ID or message domain from a scalar, concatenated string or "\Shopsys\FrameworkBundle\Component\Translation\Translator" class constant, but got "PhpParser\Node\Expr\ConstFetch".

// null is not accepted even though it's the default value. Maybe domain should not be nullable and Translator::DEFAULT_DOMAIN should be the default value

Maybe it would be nice to check following (I suspect it will not extract into proper translation domain file)

t('my string', domain: 'another-translation-domain')

Expected behavior

No error is raised 🙂

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

No branches or pull requests

2 participants