Google Transliterate translation in a rich faces page using java script
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.L开发者_C百科anguageCode.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.
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>
精彩评论