Hi, I have actually been trying to come up with a similar solution also with my Twitter App as I want to translate the tweet but not translate peoples user names @username and #hashtags (for obvious reasons).
I first tried to convert them to Hex but ran into problems, so I went with plan B which was to escape them. I don't mean the spaces and such like with javascripts escape(string) but instead used a custom wrapper to escape all the text. The problem I then ran into is Google keeps messing with my code. Example, the escaped text such as Hi! = %48%69%21 I would get back as % 48% 69% 21 You can see the problem there (same with @username = @ username and same with the #hashtags) so what I did was escape the text and replace the % with underscores (one of the few things Google seemed to leave alone), then reversed the process in my callback function. This seems to work OK for me now with the tests I have done. Not the most eloquent way I know, but due to the way Google was breaking things this seemed to be the only way so far I have come up with for this. I have been meaning to discuss this with the Google Devs. (and the translations in to Yoda - yeah the green guy from Star Wars) Since tweets are only 140 characters I didn't really need to worry too much about the URL length limit with GET requests, but due to the extra encoding I would suggest using AJAX with a POST request to get up to ~5000 characters (IIRC) to give you some extra flexibility. With your button text (if there isn't a lot of them), you can maybe try to grab the values (by DOM methods) and do the translations on page load or when there is the most chance of not as many events firing and store them in an object to be ready to go when the user selects a drop down for the language (or what ever method your using) or store them in a database or JSON string (in a static page for example may provide less latency) to call using AJAX/JSONP or something. I don't think you would need to make these requests every time if the button text values don't change, so I may personally opt for storing them in a static page as a JSON string and call that with standard AJAX or JSONP calls. Hope that helps some and if you need to see my translation escape wrappers just post back or let me know (reply to author) and I can provide some code snippets that I have been using. Cheers! Vision Jinx On Jul 28, 3:58 pm, DaveSawers <[email protected]> wrote: > I am developing a large AJAX application for the oil business. My > client wants me to produce both a French and a Russian version of the > application (with other languages later). My idea was to use Google > Translate for the majority of the text with some specific translations > held on a database table when your automatic translation is less than > perfect. I think it will work out OK. But... > > I started by translating some text that is going to go into a dialog > box. This text contains HTML tags which are not translated (generally > a good thing), except that I would like to be able to tell it to > translate the text that is displayed on buttons and some of the > initial text that is displayed in text boxes. > > Also, there is some text that is outside the HTML that I don't want > translated. These are things like specific names such as "West Texas > Sour", the name of a crude oil. > > So what I want is a way to mark portions of the text that should be > translated even though by default they wouldn't be and a way to mark > some other areas of text that shouldn't be translated even though by > default they would be. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-AJAX-Search-API?hl=en -~----------~----~----~----~------~----~------~--~---
