~stomato463/+junk/nvdajp

« back to all changes in this revision

Viewing changes to source/languageHandler.py

  • Committer: Masataka Shinke
  • Date: 2011-10-25 12:35:26 UTC
  • mfrom: (4185 jpmain)
  • mto: This revision was merged to the branch mainline in revision 4211.
  • Revision ID: mshinke@users.sourceforge.jp-20111025123526-ze527a2rl3z0g2ky
lp:~nishimotz/nvdajp/main : 4185 をマージ

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
                        LCID=0
34
34
        return LCID
35
35
 
 
36
def getLanguageDescription(language):
 
37
        """Finds out the description (licalized full name) of a given local name"""
 
38
        LCID=localeNameToWindowsLCID(language)
 
39
        if LCID==0: return None
 
40
        buf=ctypes.create_unicode_buffer(1024)
 
41
        #If the original locale didn't have country info (was just language) then make sure we just get language from Windows
 
42
        if '_' not in language:
 
43
                res=ctypes.windll.kernel32.GetLocaleInfoW(LCID,LOCALE_SLANGDISPLAYNAME,buf,1024)
 
44
        else:
 
45
                res=0
 
46
        if res==0:
 
47
                res=ctypes.windll.kernel32.GetLocaleInfoW(LCID,LOCALE_SLANGUAGE,buf,1024)
 
48
        sLanguage=buf.value
 
49
        return sLanguage
 
50
 
36
51
def getAvailableLanguages():
37
52
        """generates a list of locale names, plus their full localized language and country names.
38
53
        @rtype: list of tuples
47
62
        #For each locale, ask Windows for its human readable display name
48
63
        d=[]
49
64
        for i in l:
50
 
                LCID=localeNameToWindowsLCID(i)
51
 
                buf=ctypes.create_unicode_buffer(1024)
52
 
                #If the original locale didn't have country info (was just language) then make sure we just get language from Windows
53
 
                if '_' not in i:
54
 
                        res=ctypes.windll.kernel32.GetLocaleInfoW(LCID,LOCALE_SLANGDISPLAYNAME,buf,1024)
55
 
                else:
56
 
                        res=0
57
 
                if res==0:
58
 
                        res=ctypes.windll.kernel32.GetLocaleInfoW(LCID,LOCALE_SLANGUAGE,buf,1024)
59
 
                sLanguage=buf.value
60
 
                label="%s, %s"%(sLanguage,i)
 
65
                desc=getLanguageDescription(i)
 
66
                label="%s, %s"%(desc,i) if desc else i
61
67
                d.append(label)
62
68
        #include a 'user default, windows' language, which just represents the default language for this user account
63
69
        l.append("Windows")
101
107
 
102
108
def getLanguage():
103
109
        return curLang
 
110
 
 
111
def normalizeLanguage(lang):
 
112
        """
 
113
        Normalizes a  language-dialect string  in to a standard form we can deal with.
 
114
        Converts  any dash to underline, and makes sure that language is lowercase and dialect is upercase.
 
115
        """
 
116
        lang=lang.replace('-','_')
 
117
        ld=lang.split('_')
 
118
        ld[0]=ld[0].lower()
 
119
        #Filter out meta languages such as x-western
 
120
        if ld[0]=='x':
 
121
                return None
 
122
        if len(ld)>=2:
 
123
                ld[1]=ld[1].upper()
 
124
        return "_".join(ld)
 
125
 
 
126