Module Language
[hide private]
[frames] | no frames]

Source Code for Module Language

 1  ##################################################################### 
 2  # -*- coding: iso-8859-1 -*-                                        # 
 3  #                                                                   # 
 4  # Frets on Fire                                                     # 
 5  # Copyright (C) 2006 Sami Kyöstilä                                  # 
 6  #                                                                   # 
 7  # This program is free software; you can redistribute it and/or     # 
 8  # modify it under the terms of the GNU General Public License       # 
 9  # as published by the Free Software Foundation; either version 2    # 
10  # of the License, or (at your option) any later version.            # 
11  #                                                                   # 
12  # This program is distributed in the hope that it will be useful,   # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of    # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     # 
15  # GNU General Public License for more details.                      # 
16  #                                                                   # 
17  # You should have received a copy of the GNU General Public License # 
18  # along with this program; if not, write to the Free Software       # 
19  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,        # 
20  # MA  02110-1301, USA.                                              # 
21  ##################################################################### 
22   
23  import Config 
24  import Version 
25  import Log 
26  import gettext 
27  import os 
28  import glob 
29   
30  Config.define("game", "language", str, "") 
31   
32 -def getAvailableLanguages():
33 return [os.path.basename(l).capitalize().replace(".mo", "").replace("_", " ") for l in glob.glob(os.path.join(Version.dataPath(), "translations", "*.mo"))]
34
35 -def dummyTranslator(string):
36 return string
37 38 language = Config.load(Version.appName() + ".ini").get("game", "language") 39 _ = dummyTranslator 40 41 if language: 42 try: 43 trFile = os.path.join(Version.dataPath(), "translations", "%s.mo" % language.lower().replace(" ", "_")) 44 catalog = gettext.GNUTranslations(open(trFile, "rb"))
45 - def translate(m):
46 return catalog.gettext(m).decode("utf-8")
47 _ = translate 48 except Exception, x: 49 Log.warn("Unable to select language '%s': %s" % (language, x)) 50 language = None 51 52 # Define the config key again now that we have some options for it 53 langOptions = {"": "English"} 54 for lang in getAvailableLanguages(): 55 langOptions[lang] = _(lang) 56 Config.define("game", "language", str, "", _("Language"), langOptions) 57