2

I'm relatively new to programming and recently I've started playing around with pygame (set of modules to write games in python). I'm looking to create a program/game in which some of the labels, strings, buttons, etc are in Arabic. I'm guessing that pygame has to support Arabic letters and it probably doesn't? Or could I possibly use another GUI library that does support Arabic and use that in unison with pygame? Any direction would be much appreciated!

  • 2
    One obstacle you may face is that pygame does not (currently) support rendering of right-to-left languages such as Arabic: http://pygame.motherhamster.org/bugzilla/show_bug.cgi?id=61. The link may be helpful anyway since it shows a workaround and some example code. – unutbu Jun 18 '11 at 19:28

3 Answers3

5

Well Python itself uses Unicode for everything so that's not the problem. A quick googling also shows that PyGame should be able to render Unicode fonts just fine. So I assume the problem is more that it can't find fonts for the specific language to use for rendering.

Here is a short example for PyGame and especially this link should be useful.

This is the important library - so specifying a font that can render your language and using it to render it should work fine. Probably a good idea to write a small wrapper

Nb: Haven't used PyGame myself so this is based on speculation and some quick search about how PyGame renders fonts.

PS: If you want the game to work reliably for all of your users, it's probably a good idea to include an Open Source font in your release, otherwise you need some methodology to check if the user has some fonts installed that will work fine - a probably non-trivial problem if you want Xplattform support.

Community
  • 1
  • 1
Voo
  • 29,040
  • 11
  • 82
  • 156
0

Python does support unicode-coded source.

Set the coding of your source file to the right type with a line of the form # coding: [yourCoding] at the very beginning of your file. I think # coding: utf-8 works for Arabic.

Then prepend your string literals with a u, like so:

u'アク'

(Sorry if you don't have a Japanese font installed, it's the only one I had handy!)

This makes python treat them as unicode characters. There's further information specific to Arabic on this site.

0

Both previous answers are great. There is also a great built-in python function called unicode. It's very easy to use. I wanted to write Hebrew text so I wrote a function:

def hebrew(text):
    # Encoding that supports hebrew + punctuation marks
    return unicode(text,  "Windows-1255")

Then you can call it using:

hebrew("<Hebrew text>")

And it will return your text Hebrew encoded.

speller
  • 1,641
  • 2
  • 20
  • 27
  • 1
    Uh, how does that help exactly? Changing the encoding from Unicode to Windows-1255 reduces the number of languages you can use... – Andrea Jun 18 '11 at 21:54
  • Yeah I'd assume that if he's writing a PyGame for an Arabic audience he's already using some arabic strings in the source files, which means he's already using UTF-8 or something as the base encoding (another good thing about python3) – Voo Jun 18 '11 at 23:09