Modifying object{FieldName:value within a function?
The language code below, belonging to the function further below, contains what I believe are object fieldname values: 'en' & 'fr'.
how can these values be modified - replaced by another code?
Replacing the values with a variable so far, has not worked.
Code:
new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'fr',layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL, autoDisplay: false})
Code:
var thetext;
function googleTranslateElementInit(txt){
thetext=txt;
document.getElementById('thetext').innerHTML=txt;
new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'fr',layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL, autoDisplay: false});
setTimeout(checkIt,2000)}
function checkIt(){var thediv=document.getElementById('thetext')
res=thediv.innerText?thediv.innerText:thediv.textContent;if(thetext!=res){parent.frames['theframe2'].googleTranslateElementInit(thediv.textContent);}
else{setTimeout(checkIt,2000)}}
I can't get this to work.
I've spent a good day scouring the web for any further knowledge, but as usual, all the examples seem to be using return for anything but my scenario.
Similarly with the value..... one or two people working with the fieldname, but not with the value.
So close to a workable sys, but always another bridge to cross.
quoting line 363 as the problem.
Certainly at the end of that line and beginning next, ref is made to includedLanguages.
I again tried entering the var lang, in place of 'fr', however, this produced no errors at all, and the doc translated perfectly in its default french.
So a simple variable doesn't break the script..... it is simply ignored.
Note: replacing 'fr' with de (no quotes).
Uncaught ReferenceError: de is not defined
Anybody care to comment...... does return still hold development promise, or should another avenue be followed.
Can you show your live page? Give us the URL to look at?
From everything I have read, you aren't using googleTranslateElementInit correctly. The usages I have seen do *NOT* allow you to pass in an argument (as you are doing with your txt argument.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Hopefully you can see thru testing, where I've gone wrong.
At the moment, I am dubious of your stance on the passing of the argument.
Quote:
Originally Posted by Old Pedant
you aren't using googleTranslateElementInit correctly. The usages I have seen do *NOT* allow you to pass in an argument (as you are doing with your txt argument.
The reason being, that this element appears to work v.well.
xelawho was the force in opening up the complexities of googleTranslateElementInit
It was a major bridge crossing, but obviously everything is up for debate.
From what I know:
Given the physical transformation of the two digit code 'en', 'fr','de' etc.
The result is as expected.
I believe therefore, that the problem IS focussed upon THAT transformation (thru a select derived variable).
Though, I did figure out how to do it, only it was then, well, what now?
The system is unusable for publication to the web.
However, the coding & learning project itself was a complete success...... something that couldn't have been done using google api, without first having security in place (due to their billing).
Because of the financial risks involved, I believe the correct way forward is to now look at building such a secure web site.
I've spent some time reading a large number of docs, and it seems that a set of global publishing format protocols exists.
Effectively:
Write a doc that is vast & complex
Provide a long page of undocumented links to code libraries
Write a perfectly understandable doc, that provides insufficient information
The result being that I was unable to establish a direction, whereupon I could focus my research efforts.
I'm confident that I'm not alone in experiencing this 'inability to get to grips with this area of web development'.
As a consequence I'm going to start a thread that looks at the 'security path' options available to us.