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

Passing "null" as the $locale argument to Symfony\Component\Translation\Translator::setLocale() is deprecated since Symfony 4.4 #173

Open
xsuchy09 opened this issue Dec 19, 2019 · 3 comments

Comments

@xsuchy09
Copy link

User Deprecated
Passing "null" as the $locale argument to Symfony\Component\Translation\Translator::setLocale() is deprecated since Symfony 4.4
.../kdyby/translation/src/Translator.php:100	

  Kdyby\Translation\Translator->setLocale()

 90:            IResourceLoader $loader
 91:        )
 92:        {
 93:            $this->localeResolver = $localeResolver;
 94:            $this->formatter = $formatter;
 95:            $this->catalogueCompiler = $catalogueCompiler;
 96:            $this->fallbackResolver = $fallbackResolver;
 97:            $this->translationsLoader = $loader;
 98:    
 99:            parent::__construct('', $formatter);
100:            $this->setLocale(NULL);
101:        }
@xsuchy09
Copy link
Author

xsuchy09 commented Dec 19, 2019

I didn't analyze code of Translator but maybe it is possible to add default locale from config to constructor of Translator and use it at line 100.

xsuchy09 added a commit to xsuchy09/Translation that referenced this issue Dec 19, 2019
…mfony\Component\Translation\Translator::setLocale() is deprecated since Symfony 4.4

*issue - Kdyby#173
xsuchy09 added a commit to xsuchy09/Translation that referenced this issue Dec 19, 2019
…mfony\Component\Translation\Translator::setLocale() is deprecated since Symfony 4.4

*issue - Kdyby#173
@xsuchy09
Copy link
Author

I made some changes which should fixed this issue (don't allow to set locale as null in parent class). But really didn't analyze code of Translator at all so I can not say that this is the right way how to solve it (for me not, because why to allow null in child class when parent don't allow it now - it should be removed).

@peterpp
Copy link

peterpp commented Aug 18, 2021

There is another related issue with current Symphony. Method Translator::getLocale() never returns null. So the method:

public function getLocale()
	{
		if (empty(parent::getLocale())) {
			$this->setLocale($this->localeResolver->resolve($this));
		}

		return parent::getLocale();
	}

should be changed to something like:

public function getLocale()
	{
		if (!$this->localeResolved) {
			$this->setLocale($this->localeResolver->resolve($this));
			$this->localeResolved = true;
		}

		return parent::getLocale();
	}

Without this change, language resolving doesn't work at all.

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

2 participants