All pastes #186549 Raw Edit

Someone

public text v1 · immutable
#186549 ·published 2006-09-30 03:35 UTC
rendered paste body
#---Language Class by RockStar and tweaked by Donno--#000000#FFFFFF-----------------------------------------
class Language:
    """
        Language Class
            For reading in xml for automatiacall of the selected lanauge XBMC is running in
            And for returning the string in the given langue for a specified id
        Oringally Coded by Rockstar, Recoded by Donno :D
    """
    def load(self,thepath):
        self.strings = {}
        tempstrings = []
        self.language = xbmc.getLanguage().lower()
        if os.path.exists(thepath+self.language+"\\strings.xml"):
            self.foundlang = self.language
        else:
            self.foundlang = "english"
        self.langdoc = thepath+self.foundlang+"\\strings.xml"
        print "-Loading Language: " + self.foundlang
        try:
            f=open(self.langdoc,'r')
            tempstrings=f.read()
            f.close()
        except:
            print "Error: Languagefile "+self.langdoc+" cant be opened"
            xbmcgui.Dialog().ok(__title__,"Error","Languagefile "+self.langdoc+" cant be opened")
        self.exp='<string id="(.*?)">(.*?)</string>'
        self.res=re.findall(self.exp,tempstrings)
        for stringdat in self.res:
            self.strings[int(stringdat[0])] = str(stringdat[1])

    def string(self,number):
        if int(number) in self.strings:
            return self.strings[int(number)]
        else:
            return "unknown string id"