silverstripe / developer-docs

Developer documentation for Silverstripe CMS
Other
6 stars 66 forks source link

Requirements::add_i18n_javascript() don't work with paths from ModuleResourceLoader::resourceURL() #28

Open wernerkrauss opened 5 years ago

wernerkrauss commented 5 years ago

Affected Version

SS 4.3

Description

Cannot add i18 javascript using ModuleResourceLoader::resourceURL()

Steps to Reproduce

I try to add

Requirements::add_i18n_javascript(
    ModuleResourceLoader::resourceURL('dnadesign/silverstripe-elemental:lang')
);

resourceURL() returns /resources/vendor/dnadesign/silverstripe-elemental/lang

This is treated as absolute path in Director::getAbsFile, therefor the lang file isn't loaded cause the file isn't found.

wernerkrauss commented 5 years ago

Digging deeper into that issue I found that I can directly pass the resourceURL to add_i18n_javascript like:

Requirements::add_i18n_javascript('dnadesign/silverstripe-elemental:client/lang');

Should this be added to the i18n docs?

robbieaverill commented 5 years ago

The way you're doing is correct and should work. We do this in some of the supported modules that have frontend translations, e.g. userforms:

https://github.com/silverstripe/silverstripe-userforms/blob/2d310a38f41b3727b03aacd58f38a48767f0987c/code/Control/UserDefinedFormController.php#L60

If you think the docs could be improved we'd welcome a PR =)