psychicsoftware
November 24, 2011
Techie

Game Localisation with Google Translate

November 24, 2011
Techie

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), especially if this person is one of professional translators.

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
--------------------------------------------------------------------------------
Mars Defender for Windows, Mac, Xperia Play
Web-player Demos of Afterburn 2150, Block Rockin, Mars Defender

Newsletter

Join Email Newsletter

 
We take your privacy seriously and will never give your details to anyone else.

Presskit

Press Kit here

Games in Development

  • The Necromancer's Tale
  • Newby Chinese

Games Released

  • Darkwind: War on Wheels
  • Let's Break Stuff!
  • Musclecar Online
  • Goblins & Gottos
  • Orbs.it
  • Mars Defender
  • Demon Pit
  • Afterburn 2150
  • Block Rockin'
  • More on Gooogle Play
  • More on iOS Appstore

Unfinished Projects “On Hiatus”

  • Zed's Dead
  • Ping Pong Planets
  • Godkin

Archives

  • March 2025
  • August 2024
  • December 2023
  • June 2022
  • April 2022
  • May 2021
  • December 2020
  • November 2020
  • October 2020
  • August 2020
  • May 2020
  • March 2020
  • October 2019
  • October 2018
  • August 2018
  • July 2018
  • January 2018
  • September 2017
  • August 2017
  • May 2017
  • July 2016
  • May 2016
  • April 2016
  • December 2015
  • November 2015
  • September 2015
  • July 2015
  • May 2015
  • April 2015
  • February 2015
  • January 2015
  • December 2014
  • October 2014
  • August 2014
  • January 2014
  • December 2013
  • September 2013
  • July 2013
  • May 2013
  • April 2013
  • March 2013
  • December 2012
  • October 2012
  • August 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • March 2006
  • February 2006
  • January 2006
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • December 1995

Categories

  • Afterburn 2150
  • Block Rockin'
  • Conferences & Events
  • Darkwind
  • Dead By Dawn
  • Demon Pit
  • Game Musings
  • Goblins & Grottos
  • Godkin
  • Guest Posts
  • Let's Break Stuff!
  • Mars Defender
  • Monster Melee
  • Musclecar Online
  • Newby Chinese
  • Orbs.it
  • PC Gamer
  • Rock Paper Shotgun
  • Techie
  • The Necromancer
  • Uncategorized
  • Zed's Dead

CyberChimps WordPress Themes

PSYCHICSOFTWARE | Psychic Games Ltd.
Sam Redfern indie games developer and university academic