1
votes

I would like to use the cakephp-users plugin in my CakePHP 3.3.3 based application, and I would like to localize that.

I am using composer to autoload the plugin.

If my understanding of the documentation is correct than the Plugin localization po file shall be the vendor/cakemanager/cakephp-users/src/Locale/hu/users.po in my case. (The path should be correct because the

    bin/cake i18n extract --plugin Users 

command generates the default.pot file to vendor/cakemanager/cakephp-users//src/Locale folder.)

The text did not get localized regardless if I use the default.po filename or users.po filename. If I move a translation to the application's localization file (src/Locale/hu/default.po) then my strings got translated. (After I delete the tmp/cache/persistent folder's contents.)

Is there anything special what I miss to get my plugin localized?

Thanks in advance!

1

1 Answers

1
votes

Third party plugin localization should be in the apps Locale folder

Your assumption that the files should be in the plugin folder is not necessarily correct. Custom localizations for third party code should be in the applications Locale folder, otherwise they would get lost everytime the code package is being updated.

You may want to report the behavior that the shell by default wants to extract all plugin localization into the plugins Locale folder as an issue. Personally I think it would be good if it wouldn't try that in case the plugin lives in the vendors folder.

Until that, you should use the --output option to specifiy the proper path to your applications Locale folder.

First party plugin localization might go in the plugins Locale folder

If it were your own plugin, and you wanted to ship it with ready made translations, then they should be in the plugins Locale folder, however nothing should be added afterwards if the plugin is a standalone plugin that is being included via composer, because again, these changes would get lost on update.

You should only add further localizations in a plugins Locale folder in case the plugin is tied directly to your application, and therefore lives in the applications plugins folder.

cakemanager/cakephp-users doesn't follow the conventions

All that being said, cakemanager/cakephp-users is a special case, it doesn't follow the conventions of using domain translation methods like __d(), and supplying a domain name that is the lowercased, underscored variant of the plugin name, like __d('users', 'message text').

Instead it uses domain less translation calls, ie __('message text'), see for example

https://github.com/cakemanager/cakephp-users/...src/Controller/UsersController.php#L75

Therefore CakePHPs message file loader will never try to load any localization files from the plugins Locale folder in the first place, and it also won't look up proper separate localization files in your apps Locale folder.

So with this specific plugin, in its current form, the translations have to go in your applications default translation file.

See also