translate.js icon indicating copy to clipboard operation
translate.js copied to clipboard

Not sure to understand

Open cyberlp23 opened this issue 6 years ago • 1 comments

Hello, Sorry, i'm not sure to understand how this works. Should I only add something like this? It doesn't seem to work. Well, it does recognize the right language defined in $('body').translate({lang: "en", t: dict}); , but nothing happens when clicking on the translation buttons. Also, do I need in the var dict to put the whole text of the variable, or can I use for example the id of an element? Thanks!

	<p class="trn">to be translated</p>

           <a class="btn btn-default lang_selector trn" href="#" role="button" data-value="en">EN</a>
            <a class="btn btn-default lang_selector trn" href="#" role="button"  data-value="fr">FR</a>


	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
	<script src="jquery.translate.js"/>
	<script type="text/javascript">
		var dict = {
			"to be translated": {
				en: "the translation",
fr: "la traduction"
			}
		}
		$('body').translate({lang: "en", t: dict}); 
	</script>

cyberlp23 avatar Jan 19 '19 22:01 cyberlp23

@cyberlp23 Here is a working JSFiddle for you.

I notice 3 issues in your above code:

  1. Your dict object should have the keys as strings, but you haven't written them as such. It should be enclosed within ".

  2. You have to instantiate the translate. After instantiating you should call the translate method.

var translator = $('body').translate({lang: "en", t: dict}); translator.lang("pt"); // Mention the language you want to translate to

  1. You need to add an event listener on the buttons to help translate. This you haven't added.

Check the above fiddle I have shared. It should be of help to you.

mohammedFurqan avatar Mar 17 '19 09:03 mohammedFurqan