Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-24-2012, 03:11 PM   PM User | #1
Ace.....
New Coder

 
Join Date: Nov 2012
Location: France
Posts: 78
Thanks: 20
Thanked 0 Times in 0 Posts
Ace..... is an unknown quantity at this point
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)}}
Ace..... is offline   Reply With Quote
Old 11-24-2012, 08:52 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,451
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
If you want to replace 'en' with a variable called lang then you'd replace the 'en' with function() {return lang;}
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 11-25-2012, 03:48 PM   PM User | #3
Ace.....
New Coder

 
Join Date: Nov 2012
Location: France
Posts: 78
Thanks: 20
Thanked 0 Times in 0 Posts
Ace..... is an unknown quantity at this point
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.

Can anybody else shed some light on this.
Ace..... is offline   Reply With Quote
Old 11-26-2012, 06:14 PM   PM User | #4
Ace.....
New Coder

 
Join Date: Nov 2012
Location: France
Posts: 78
Thanks: 20
Thanked 0 Times in 0 Posts
Ace..... is an unknown quantity at this point
Quote:
Originally Posted by felgall View Post
If you want to replace 'en' with a variable called lang then you'd replace the 'en' with function() {return lang;}
Tests
Code:
var lang = "'de'"; (and subsequently) 
var lang = 'de';

({pageLanguage: 'en', includedLanguages: function () {return lang;})
Console report:
Uncaught TypeError: Object function () {return lang;} has no method 'split'
.....................

Is it saying that the split method should have been used?
Ace..... is offline   Reply With Quote
Old 11-26-2012, 10:55 PM   PM User | #5
Ace.....
New Coder

 
Join Date: Nov 2012
Location: France
Posts: 78
Thanks: 20
Thanked 0 Times in 0 Posts
Ace..... is an unknown quantity at this point
I incorporated the split method:

Code:
var str="'de'";
var lang=str.split();
alert(lang);
The alert returns 'de' as desired.

Console report:
Uncaught TypeError: Object function () {return lang;} has no method 'split'.

However, it's source ref is:
Code:
http://translate.googleapis.com/translate_static/js/element/11/element_main.js
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.

Last edited by Ace.....; 11-26-2012 at 11:07 PM..
Ace..... is offline   Reply With Quote
Old 11-26-2012, 11:27 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 11-27-2012, 02:27 AM   PM User | #7
Ace.....
New Coder

 
Join Date: Nov 2012
Location: France
Posts: 78
Thanks: 20
Thanked 0 Times in 0 Posts
Ace..... is an unknown quantity at this point
Re: The url, you can re-test with my pleasure & anticipation

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 View Post
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).

However, I'm well prepared to be told different.
Ace..... is offline   Reply With Quote
Old 11-27-2012, 02:49 AM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Well, maybe it is just that you are using the *NAME* googleTranslateElementInit

As I said, all usages I saw that was the name of the callback function passed to
Code:
<script type="text/javascript" 
src="//translate.google.com/translate_a/element.js?callback=FUNCTIONNAMEHERE"></script>
Since you apparently don't want the page to be translated when it first appears, clearly you don't want that callback function.

Anyway, this *SHOULD* be easy. You are working too hard.

You just need to PASS IN the languages to your function!

Back later.
__________________
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.
Old Pedant is offline   Reply With Quote
Old 12-08-2012, 04:17 PM   PM User | #9
Ace.....
New Coder

 
Join Date: Nov 2012
Location: France
Posts: 78
Thanks: 20
Thanked 0 Times in 0 Posts
Ace..... is an unknown quantity at this point
Yes you are of course right.

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:
  1. Write a doc that is vast & complex
  2. Provide a long page of undocumented links to code libraries
  3. 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.
Ace..... is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:48 PM.


Advertisement
Log in to turn off these ads.