Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted December 28, 20159 yr 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"}.
December 28, 20159 yr Normal: ips.getString('key') With %s: ips.getString('key', { parameter1, parametr2 etc } ) With pluralize: ips.pluralize( ips.getString( 'key' ), parameter )
December 28, 20159 yr 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.
December 28, 20159 yr Author 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?
December 28, 20159 yr Author 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?
December 28, 20159 yr 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.
Archived
This topic is now archived and is closed to further replies.