Displaying all characters in translated text

Hi
After some useful help from you experts I am close to getting my flash traslator to work the way I need it to (latest code is shown here). One issue remains and that is I am losing upper case letters and some other extended characters. By using the trace option I can see that what is returned from Google Translate is correct:

Esta parte es sólo un texto al azar para ver cómo se las arregla el traductor con palabras como: alternador, motor, transmisión y tyres.And esta parte es para probar cómo "las marcas de expresión" y el trabajo "apóstrofe" ¿Qué piensa usted?

But then what ends up in my textbox is:

sta parte es sólo un texto al azar para ver cómo se las arregla el traductor con palabras como: alternador, motor, transmisión y los neumáticos. Y esta parte es para poner a prueba cómo las "marcas del habla" y trabajar "apóstrofe"! ¿Qué piensa usted?

The original text was:

"This part is just some random text to see how the translator copes with words like: alternator, engine, transmission and tyres.

And this part is to test how "speech marks" and 'apostrophes' work!

What do you think?"


..so I am also losing line breaks. The textbox is set as standard Arial font, classic text, dynamic text, and if just as an experiment, I paste in the version with capitals and other characters it shows fine.

Your help will again be appreciated!
Tom
on (release) {
	var lorem_lv:LoadVars = new LoadVars();
	txtLang.text = "Current language code is: " + lstLang.getSelectedItem().data;
	strLang = lstLang.getSelectedItem().data;
	btnReset._visible = true
	
	if (strLang == null) {
		strLang = "en";
		txtLang.text = lstLang.getSelectedItem().data;
	}
	lorem_lv.onData = function(src:String):Void  {
		clip(src);
	}
	strSource = escape(txtContent.text);
	lorem_lv.load("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + strSource + "&langpair=en%7C" + strLang);

	function clip(str:String):Void {
		find_me = "translatedText";
		str = str.substr(str.indexOf(find_me)+ 17, str.length);
		str = str.substr(0, str.indexOf("},")-1);
		str = unescape(str);
		
		//get rid of any ampersands
		find_me = "\\u0026";
		pos = str.indexOf(find_me);
		while (pos >= 0) {
			str = str.substr (0, pos) + "&" + str.substr(pos + find_me.length, str.length);
			pos = str.indexOf(find_me);
		}
		trace(str);
		txtContent.htmlText = str;
	}
}

Open in new window

tomdentonAsked:
Who is Participating?
 
dgofmanCommented:
Replace in this case

to_txt.text = translatedText.split('\\r').join('\n').split('\\"').join("'");
0
 
dgofmanCommented:
Because previous answers was not present a full solution, experts just fixed some problems in your code :)

      var result_lv:LoadVars = new LoadVars();
    result_lv.onLoad = function(success:Boolean) {
        if (success) {
                  var str:String = unescape(this);
                  var translatedText:String = str.split('":"')[1].split('"}, ')[0];
                  if(translatedText != undefind)
                        trace(translatedText)
        } else {
            trace("Error");
        }
    };
    var lorem_lv:LoadVars = new LoadVars();
      var from:String = "en";
      var to:String = "es";
      lorem_lv.v = "1.0";
      lorem_lv.q = "This part is just a random text to see how he manages the translator with words like";
      lorem_lv.langpair = from + "|" + to;
    lorem_lv.sendAndLoad("http://ajax.googleapis.com/ajax/services/language/translate", result_lv, "POST");
0
 
tomdentonAuthor Commented:
I did rush at a previous 'answer' sorry... :)

Many thanks for this it is much tidier and easier to follow.

I have now added: 'txtContent.htmlText = translatedText' after 'trace(translatedText) to put the result in a textbox and it works fine (I also set the text property anti alias to: Use sysem fonts, which helped)

What is now the best way of getting the original English text from the text box to send it to the translator? I tried changing the 'lorem_lv.q = "This part is just...";' to 'lorem_lv.q = escape(txtContent.text);' but I just get a blank result
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
dgofmanCommented:
Why do you want to use escape function. LoadVars will escape automatically.
Give me work scenario or key words what is not working for you
0
 
tomdentonAuthor Commented:
The text I have in the textbox to start with is:

This will test how  'apostrophes' work!

And this to check line breaks.


If i use: 'lorem_lv.q = txtContent.text;' then the result I get in trace and back into the textbox is:

Esta parte es para poner a prueba el trabajo como \u0026quot;apóstrofe\u0026quot;! Y esto para comprobar los saltos de línea.

The apostrophes seem to be a problem and I do not get the line break. For this reason I tried (due to now knowing enough!!): 'lorem_lv.q = escape(txtContent.text);' then I get nothing back in the box.
0
 
dgofmanCommented:
Is this what you want?>

_root.createTextField("from_txt", _root.getNextHighestDepth(), 0, 0, 500, 50);
var from_txt:TextField = _root["from_txt"];
from_txt.multiline = true;
from_txt.text = "This will test how  'apostrophes' work!\n\nAnd this to check line breaks.";

_root.createTextField("to_txt", _root.getNextHighestDepth(), 0, 80, 500, 50);
var to_txt:TextField = _root["to_txt"];
to_txt.multiline = true;

var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
      if (success) {
                    var str:String = unescape(this);
                    var translatedText:String = str.split('":"')[1].split('"}, ')[0];
                    if(translatedText != undefind)
                              to_txt.text = translatedText.split('\\r').join('\n');
      } else {
            trace("Error");
      }
};
var lorem_lv:LoadVars = new LoadVars();
var from:String = "en";
var to:String = "es";
lorem_lv.v = "1.0";
lorem_lv.format = "text";
lorem_lv.q = from_txt.text;
lorem_lv.langpair = from + "|" + to;
lorem_lv.sendAndLoad("http://ajax.googleapis.com/ajax/services/language/translate", result_lv, "POST");
0
 
dgofmanCommented:
Esto pondrá a prueba el trabajo como 'apóstrofes'!

Y esto para verificar los saltos de línea.
0
 
tomdentonAuthor Commented:
Yes this is almost spot on :)

One small issue is that I now get the following back slashes:


Esto pondrá a prueba el trabajo como \"apóstrofe\"!

Y esto para comprobar los saltos de línea.
0
 
tomdentonAuthor Commented:
You're the man. Thanks for your help and patience with an actionscript novice!.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.