Skip to main content
deleted 37 characters in body
Source Link
Adrian Cid Almaguer
  • 18.5k
  • 14
  • 79
  • 133

I've tried to re-phrase my question in my head a million times, as there seem to be quite a number of approaches and solutions, but finally decided to ask it in a very general way:

What is the best way to localize variables in external javascript, such as help hints, tooltips, and such?

Currently I have my js pasted raw into PHP Code, in as many instances as there are languages on the site, and I'm switching the variable set based on:

<?php
  global $language;
  $lang = $language->language;
?>

but I strongly dislike having a gazillion of copies of same text throughout the site. This is good for testing, but for production I want just one javascript file which I could call with parameters, something like:

<script src="myscript.js?hl=<?php print $lang?>"><script>

Would love to learn your know-hows.

I've tried to re-phrase my question in my head a million times, as there seem to be quite a number of approaches and solutions, but finally decided to ask it in a very general way:

What is the best way to localize variables in external javascript, such as help hints, tooltips, and such?

Currently I have my js pasted raw into PHP Code, in as many instances as there are languages on the site, and I'm switching the variable set based on:

<?php
  global $language;
  $lang = $language->language;
?>

but I strongly dislike having a gazillion of copies of same text throughout the site. This is good for testing, but for production I want just one javascript file which I could call with parameters, something like:

<script src="myscript.js?hl=<?php print $lang?>"><script>

Would love to learn your know-hows.

I've tried to re-phrase my question in my head a million times, as there seem to be quite a number of approaches and solutions, but finally decided to ask it in a very general way:

What is the best way to localize variables in external javascript, such as help hints, tooltips, and such?

Currently I have my js pasted raw into PHP Code, in as many instances as there are languages on the site, and I'm switching the variable set based on:

<?php
  global $language;
  $lang = $language->language;
?>

but I strongly dislike having a gazillion of copies of same text throughout the site. This is good for testing, but for production I want just one javascript file which I could call with parameters, something like:

<script src="myscript.js?hl=<?php print $lang?>"><script>
Tweeted twitter.com/#!/StackDrupal/status/175820269666058240
Source Link
no more drupal
  • 5.5k
  • 2
  • 44
  • 84

Adding localized js

I've tried to re-phrase my question in my head a million times, as there seem to be quite a number of approaches and solutions, but finally decided to ask it in a very general way:

What is the best way to localize variables in external javascript, such as help hints, tooltips, and such?

Currently I have my js pasted raw into PHP Code, in as many instances as there are languages on the site, and I'm switching the variable set based on:

<?php
  global $language;
  $lang = $language->language;
?>

but I strongly dislike having a gazillion of copies of same text throughout the site. This is good for testing, but for production I want just one javascript file which I could call with parameters, something like:

<script src="myscript.js?hl=<?php print $lang?>"><script>

Would love to learn your know-hows.