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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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");
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
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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.
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");
dgofmanCommented:
Esto pondrá a prueba el trabajo como 'apóstrofes'!

Y esto para verificar los saltos de línea.
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.
dgofmanCommented:
Replace in this case

to_txt.text = translatedText.split('\\r').join('\n').split('\\"').join("'");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tomdentonAuthor Commented:
You're the man. Thanks for your help and patience with an actionscript novice!.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.