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

Missing translations causes exception #1252

Open
kyrill71 opened this issue Feb 18, 2025 · 1 comment
Open

Missing translations causes exception #1252

kyrill71 opened this issue Feb 18, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@kyrill71
Copy link

kyrill71 commented Feb 18, 2025

MyParcel plugin version

5.3.0

WooCommerce version

9.6.1

WordPress version

6.7.2

PHP version

8.2

What went wrong?

When using WPML, MyParcel, and WooCommerce on our site, the German version encounters an exception whenever a user tries to add something to the cart or clicks on the checkout button.

I'm not sure if this issue is specific to WPML or if it also occurs when the site is set to German without WPML.

The exception occurs because the plugin attempts to load the German translation file de.json from the following directory:
/wp-content/plugins/woocommerce-myparcel/config/pdk/translations However, the de.json file does not exist.

As a temporary solution, we copied en.json and renamed it to de.json, which resolved the issue for our German site.

Suggestion for Improvement

  1. Add a German translation file:
    It is surprising that there is no German translation, especially since many webshops also deliver to Germany. The plugin already includes English and French translations.
  2. Implement a fallback language:
    Instead of throwing an exception when a translation file is missing, the plugin should default to English (or another available language) to prevent site-breaking errors.

I hope you will consider adding a German translation and implementing a fallback mechanism in a future update.

Reproduction steps

  1. Set up a WordPress site with WPML, WooCommerce, and the MyParcel plugin, with Dutch as the main language and German as a translation.
    • Alternatively, this issue might also occur on a standalone German WordPress site with WooCommerce and MyParcel (untested, but based on the exception, it's possible that it does not work on there either).
  2. Create a product and translate it into German.
  3. Go to the frontend of the product in the German translation.
  4. Try to add the product to the cart.
  5. You will encounter an exception.

Relevant log output

PHP Fatal error: Uncaught InvalidArgumentException: File "/wp-content/plugins/woocommerce-myparcel//config/pdk/translations/de.json" does not exist. in /wp-content/plugins/woocommerce-myparcel/vendor/myparcelnl/pdk/src/Base/FileSystem.php:46 Stack trace: #0 /wp-content/plugins/woocommerce-myparcel/vendor/myparcelnl/pdk/src/Language/Service/AbstractLanguageService.php(56): MyParcelNL\Pdk\Base\FileSystem->get() #1 /wp-content/plugins/woocommerce-myparcel/vendor/myparcelnl/pdk/src/Base/Repository/Repository.php(52): MyParcelNL\Pdk\Language\Service\AbstractLanguageService->MyParcelNL\Pdk\Language\Service\{closure}() #2 /wp-content/plugins/woocommerce-myparcel/vendor/myparcelnl/pdk/src/Language/Repository/LanguageRepository.php(17): MyParcelNL\Pdk\Base\Repository\Repository->retrieve() #3 /wp-content/plugins/woocommerce-myparcel/vendor/myparcelnl/pdk/src/Language/Service/AbstractLanguageService.php(55): MyParcelNL\Pdk\Language\Repository\LanguageRepository->getTranslations() #4 /wp-content/plugins/woocommerce-myparcel/vendor/myparcelnl/pdk/src/Language/Service/AbstractLanguageService.php(77): MyParcelNL\Pdk\Language\Service\AbstractLanguageService->getTranslations()

Additional context

No response

@FreekVR
Copy link
Collaborator

FreekVR commented Feb 21, 2025

Thanks for submitting this issue! The plugin should actually use english as a fallback language if the language is not supported (which is the case for Germany at this point in time). Unfortunately it looks like there was an issue in our underlying plugin development kit, which I've fixed. Once it's gone through our review & testing process it'll be included in the next version of our plugin(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants