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

Add missing translations #260

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gschrisstadler
Copy link

@gschrisstadler gschrisstadler commented Sep 19, 2024

This commit adds missing translation targets in multiple languages. The reason for this commit is that when I clear or warmup the cache in Contao 5+, it returns the following warning stating missing translations but also an error in the same file afterward.

[2024-09-17T10:11:30.119509+02:00] php.WARNING: Warning: Undefined array key "gotoLanguage" {"exception":"[object] (ErrorException(code: 0): Warning: Undefined array key \"gotoLanguage\" at /vendor/terminal42/contao-changelanguage/src/Navigation/NavigationFactory.php:56)"} {"request_uri":"/de/home","request_method":"GET"}
[2024-09-17T10:11:30.119835+02:00] request.CRITICAL: Uncaught PHP Exception TypeError: "sprintf(): Argument #1 ($format) must be of type string, null given" at NavigationFactory.php line 56 {"exception":"[object] (TypeError(code: 0): sprintf(): Argument #1 ($format) must be of type string, null given at /vendor/terminal42/contao-changelanguage/src/Navigation/NavigationFactory.php:56)"} {"request_uri":"/de/home","request_method":"GET"}

Once I added the translations, the error went away. I am unsure if this might also be able to be mitigated by changing lines 54-58 to the following:

$item->setAriaLabel(
    $item->isDirectFallback()
         ? \sprintf(&$GLOBALS['TL_LANG']['MSC']['gotoLanguage'], $this->locales[$item->getLocaleId()])
         : \sprintf(&$GLOBALS['TL_LANG']['MSC']['switchLanguageTo'][1], $this->locales[$item->getLocaleId()]),
);

@fritzmg
Copy link
Contributor

fritzmg commented Sep 19, 2024

I think translations are managed on Transifex, you'd have to apply as a translator for these languages there.

Regarding the error itself: this should probably be fixed by using the Translator instead of accessing $GLOBALS['TL_LANG'] directly.

@aschempp
Copy link
Member

Yes, translations are managed in Transifex, same as Contao: https://app.transifex.com/terminal42/contao-changelanguage/

Regarding the error, this shouldn't happen in a default Contao website. Contao always loads the english language first, and then the actual language. So there should always be a fallback label and not this error. Is this in a custom entry point or something like that?

@gschrisstadler
Copy link
Author

@fritzmg thanks, I didn't manage to get it working with the Translator, so I just added the required translations on our project directly.

@aschempp it happened on a Contao 5.3 project with PHP 8.3. whenever the language switcher was loaded in the frontend we would get the warning above, but it would show as an error page if the APP_ENV wasn't set to prod

@fritzmg
Copy link
Contributor

fritzmg commented Nov 26, 2024

Can you post the full stack trace?

@aschempp
Copy link
Member

whenever the language switcher was loaded in the frontend we would get the warning above, but it would show as an error page if the APP_ENV wasn't set to prod

And this was just a regular Contao website setup with no special pages (e.g. a custom page controller)?

@gschrisstadler
Copy link
Author

@fritzmg I tried to replicate the problem again, but I can't. maybe it was something else that was making this error appear? 🙈

@aschempp this was a regular contao website it was in a custom DCA with custom content elements, but no special page controllers

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

Successfully merging this pull request may close these issues.

3 participants