views:

21

answers:

1

Hello,

I am trying to use google transliterate and translate some text from english to a diffrent language. I am able to do this using the following code in the javascript.

  var options = {
                                  sourceLanguage:
                                      google.elements.transliteration.LanguageCode.ENGLISH,
                                  destinationLanguage:
                                      [google.elements.transliteration.LanguageCode.GERMAN],
                                  shortcutKey: 'ctrl+g',
                                  transliterationEnabled: true
                              };

Now this is static code so i can only translate english to German. I have Rich faces code which changes the language to a couple of types i get the value that needs to be translated in a particular page as a bean property something like a

<ui:param name="mcLanguage" value="#{mcLanguageHome.instance.getLanguageType()}"/>

so my question is .. is there a way i can pass this on a particular page to my javascript file. So i can change the language accordingly.

+1  A: 

You can create create your javascript file with a variable:

 <script>
    function translate(lang){
     var options = {
             sourceLanguage:                google.elements.transliteration.LanguageCode.ENGLISH,
             destinationLanguage:
                                 [google.elements.transliteration.LanguageCode.+ lang+ ],
                                      shortcutKey: 'ctrl+g',
                                      transliterationEnabled: true
                                  };

}

    </script>

and call the javascript:

<h:body onload="translate(#{mcLanguageHome.instance.getLanguageType()})" >
...
</h:body>
Odelya
Thank you for the answer, just to clarify a few things i will be using this script http://code.google.com/apis/ajax/playground/#transliterate_hindihere now this will probably work if i put the script inside the script on the page ... what happens if want to load the script of a link ... since i will be using the same script from multiple pages. Will the above work in that case.
Jeremiah
if you want to load script from a link you can use: <script language="javascript" type="text/javascript" src ="#{bean.source}">where bean.source is dynamic from the bean
Odelya
unfortunately this doesnt seem to work ... it works if its on page... and i use something like this destinationLanguage: [google.elements.transliteration.LanguageCode.#{mcLanguage}],but the moment the code is moved to a seperate file it doesnt work... i changed the code like this ... on the src file var lang=#{mcLanguage}function OnLoad() { translate(lang);}on the javascript file called the destination language line as followsgoogle.elements.transliteration.LanguageCode.+ lang+i keep getting a unidetified token + error msg.
Jeremiah