Game Localisation with Google Translate

I recently wrote a Javascript-based tool which uses the Google Translate Ajax API to translate English phrases, as pasted into a textbox, into other languages. Pretty handy for games. Although the results from Google Translate can be a bit dodgy, I have found that they’re good enough to get version 1 done, and hopefully some interested player will come forward and offer to make improvements (they have for me, anyway).

Each English phrase should be separated by a line-break, and there’s two output options:

1. If you choose a single translation language, you get the English and other language phrases interleaved in your output. So you can store each language in a separate file. This is what I used for the Darkwind client translations.

2. If you click ‘all to XML’ you’ll get a node per phrase, with each language’s translation as a parameter of the node. I have been using this in my Shiva games.. since Shiva data files are always in XML format, this gives me exactly what I need.

You can try it out here

And here’s some Lua code I have been using in Shiva to take a phrase and return its translation (it’s assumed that GameMainAI has a member variable called ‘sLanguage’ which is the target language, e.g. “uk”, “de”, “es”, “it”, “pt”):


--------------------------------------------------------------------------------
function GameMainAI.doLocaliseOneString ( sEnglish, hXMLTable )
--------------------------------------------------------------------------------

local lang = this.sLanguage ( )
local sTranslated = ""

if ( lang=="uk" ) then
   -- special case: English
   sTranslated = sEnglish
else
   local hRoot = xml.getRootElement ( hXMLTable )
   local count = xml.getElementChildCount ( hRoot )
   if ( count > 0 ) then
      for i=0, count-1 do
         local hElem = xml.getElementChildAt ( hRoot, i )
         local sPhrase = xml.getElementValue ( hElem )
         if ( sPhrase==sEnglish ) then
            local hAttrib = xml.getElementAttributeWithName ( hElem, lang )
            if ( hAttrib ) then
               sTranslated = xml.getAttributeValue ( hAttrib )
            end
            break
         end
      end
   end
end

if (string.getLength ( sTranslated )<1) then
   sTranslated = sEnglish -- something went wrong, so revert to the English original
end

return sTranslated

 

--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------
Responses are currently closed, but you can trackback from your own site.

 

Comments are closed.