Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
motomac Posted December 28, 2015 Posted December 28, 2015 I'm making a plugin, main logic of which is in the Javascript controller (dev/js/myscript.js). Is there any easy way to use language strings in this external Javascript file? Now I have to manually assign needed strings to Javascript variables in the template like this: var today = {lang="today"}; But I need a lot of language strings, and it's becoming too hard to use this approach. The same question with the other template plugins like {setting="$settingKey"}.
Ilya Hoilik Posted December 28, 2015 Posted December 28, 2015 Normal: ips.getString('key') With %s: ips.getString('key', { parameter1, parametr2 etc } ) With pluralize: ips.pluralize( ips.getString( 'key' ), parameter )
bfarber Posted December 28, 2015 Posted December 28, 2015 Yes, don't assign language strings to variables - in your js file just use the appropriate methods (as @Ilya Hoilik showed) to fetch the strings where needed.
motomac Posted December 28, 2015 Author Posted December 28, 2015 Thank you very much, @Ilya Hoilik and @bfarber! As I understand this allows us to use only current plugin's language strings, not all. Am I right?
motomac Posted December 28, 2015 Author Posted December 28, 2015 And the second question about the settings. As I see in the code, I can't simply use getSetting(settingKey) without predefining settings using ips.setSetting(settingKey) in the templates. Is it a correct way?
bfarber Posted December 28, 2015 Posted December 28, 2015 Hello, You can reference any language string - ultimately javascript language strings are all set in the same manner and are globally accessible. That is correct about setSetting/getSetting. Not all ACP settings are passed to javascript inherently, you will need to manually pass any that you want to access.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.