Kdyby / Translation

Integration of Symfony/Translation into Nette Framework
https://packagist.org/packages/kdyby/translation
Other
89 stars 84 forks source link

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

Open xsuchy09 opened 4 years ago

xsuchy09 commented 4 years ago
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 commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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.