area17 / twill

Twill is an open source CMS toolkit for Laravel that helps developers rapidly create a custom admin console that is intuitive, powerful and flexible. Chat with us on Discord at https://discord.gg/cnWk7EFv8R.
https://twillcms.com
Apache License 2.0
3.72k stars 568 forks source link

TwillCapsule translations are not working because of invalid registering of translation namespace (arguments order) #2476

Closed emanueljacob closed 6 months ago

emanueljacob commented 6 months ago

Description

When adding Twill capsules it is possible to use translations. To make it work Twill uses a callback to register the capsules translation namespace.

However the order of the parameter list is invalid, and the translation is not being applied.

actual

as you can see the addNamespace method is being called with the capsules translation path as first argument, and the namespace as second argument:

$callback = function (Translator $translator) {
    // actual (invalid)
    $translator->addNamespace($this->getLanguagesPath(), 'twill:capsules:' . $this->getModule());
};

Source:

expected (correct)

the addNamespace method should be called with the namespace as first argument, and the capsules translation path as second argument

$callback = function (Translator $translator) {
    // correct call
    $translator->addNamespace('twill:capsules:' . $this->getModule(), $this->getLanguagesPath());
};

Steps to reproduce

Because this is a bug in the twill capsule implementation, to reproduce it it is crucial to create a twill capsule.

  1. Create and register a capsule including a translation
  2. Add a form with a translated field that has a translation in the capsule directory (see following screenshot for an example)
  3. Open the capsules form wherever you may have introduced it
  4. check whether the translation has been applied or not
image

Expected result

After checking 4.) one should see the translated string, that is defined in the language file, dependened on the set locale.

Actual result

After checking 4.) one sees the language string of the twill capsule. For example, considering the name of the Capsule was HelloWorld and the translatable string was in a file lang/en/form.php and had the key demo, the displayed string is: twill:capsule:helloWorld::form.demo.

Versions

Twill version: 3.1.0 Laravel version: 10.43 PHP version: 8.2 || 8.3 Database engine: MySQL