home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.4)
-
- '''
- Language module
-
- Nuka1195
- '''
- import os
- import xbmc
- import xml.dom.minidom as xml
-
- class Language:
- ''' Language Class: creates a dictionary of localized strings { int: string } '''
-
- def __init__(self):
- ''' initializer '''
- base_path = os.path.join(os.getcwd().replace(';', ''), 'resources', 'language')
- language = self._get_language(base_path)
- self._create_localized_dict(base_path, language)
-
-
- def _get_language(self, base_path):
- ''' returns the current language if a strings.xml file exists else returns english '''
- language = xbmc.getLanguage().lower()
- if not os.path.isfile(os.path.join(base_path, language, 'strings.xml')):
- language = 'english'
-
- return language
-
-
- def _create_localized_dict(self, base_path, language):
- ''' initializes self.strings and calls _parse_strings_file '''
- self.strings = { }
- self._parse_strings_file(os.path.join(base_path, language, 'strings.xml'))
- if language != 'english':
- self._parse_strings_file(os.path.join(base_path, 'english', 'strings.xml'))
-
-
-
- def _parse_strings_file(self, language_path):
- ''' adds localized strings to self.strings dictionary '''
-
- try:
- doc = xml.dom.minidom.parse(language_path)
- root = doc.documentElement
- if not root or root.tagName != 'strings':
- raise
-
- strings = root.getElementsByTagName('string')
- for string in strings:
- string_id = int(string.getAttribute('id'))
- if string_id not in self.strings and string.hasChildNodes():
- self.strings[string_id] = string.firstChild.nodeValue
- continue
- except:
- xbmc.output("ERROR: Language file %s can't be parsed!" % (language_path,))
-
-
- try:
- doc.unlink()
- except:
- pass
-
-
-
- def localized(self, code):
- ''' returns the localized string if it exists '''
- return self.strings.get(code, 'Invailid Id %d' % (code,))
-
-
-