[Nvda-dev] commit r1968 - in trunk/source: . gui

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Nvda-dev] commit r1968 - in trunk/source: . gui

NVDA Subversion
Author: mdcurran
Date: Sat Apr 26 03:22:30 2008
New Revision: 1968

Log:
Display full language names in the language combo box in the general settings dialog, rather than just the locale identifiers. We now ask Windows for these language names, apparently the names are localized to the version of Windows you have, but as I have only English Windows I can't test this -- all names show in English for me. Also, English (en) is no longer near the bottom of the list, it is now where it should be in alphabetical order. Hopefully these changes will make it a bit easier for users to choose an NVDA language.

Modified:
   trunk/source/gui/settingsDialogs.py
   trunk/source/languageHandler.py

Modified: trunk/source/gui/settingsDialogs.py
==============================================================================
--- trunk/source/gui/settingsDialogs.py (original)
+++ trunk/source/gui/settingsDialogs.py Sat Apr 26 03:22:30 2008
@@ -103,10 +103,10 @@
  languageSizer.Add(languageLabel)
  languageListID=wx.NewId()
  self.languageNames=languageHandler.getAvailableLanguages()
- self.languageList=wx.Choice(self,languageListID,name=_("Language"),choices=self.languageNames)
+ self.languageList=wx.Choice(self,languageListID,name=_("Language"),choices=[x[1] for x in self.languageNames])
  try:
  self.oldLanguage=config.conf["general"]["language"]
- index=self.languageNames.index(self.oldLanguage)
+ index=[x[0] for x in self.languageNames].index(self.oldLanguage)
  self.languageList.SetSelection(index)
  except:
  pass
@@ -136,7 +136,7 @@
  self.languageList.SetFocus()
 
  def onOk(self,evt):
- newLanguage=self.languageNames[self.languageList.GetSelection()]
+ newLanguage=[x[0] for x in self.languageNames][self.languageList.GetSelection()]
  if newLanguage!=self.oldLanguage:
  try:
  languageHandler.setLanguage(newLanguage)

Modified: trunk/source/languageHandler.py
==============================================================================
--- trunk/source/languageHandler.py (original)
+++ trunk/source/languageHandler.py Sat Apr 26 03:22:30 2008
@@ -5,21 +5,54 @@
 import gettext
 import globalVars
 
+#a few Windows locale constants
+LOCALE_SLANGUAGE=0x2
+LOCALE_SLANGDISPLAYNAME=0x6f
+
 curLang="en"
 
 def getAvailableLanguages():
+ """generates a list of locale names, plus their full localized language and country names.
+ @rtype: list of tuples
+ """
+ #Make a list of all the locales found in NVDA's locale dir
  l=[x for x in os.listdir('locale') if not x.startswith('.')]
  l=[x for x in l if os.path.isfile('locale/%s/LC_MESSAGES/nvda.mo'%x)]
+ #Make sure that en (english) is in the list as it may not have any locale files, but is default
  if 'en' not in l:
  l.append('en')
+ l.sort()
+ #For each locale, ask Windows for its human readable display name
+ d=[]
+ for i in l:
+ #Windows only excepts full locales (with country included) and uses a dash not underscore
+ t=locale.normalize(i)
+ if '.' in t:
+ t=t.split('.')[0]
+ t=t.replace('_','-')
+ LCID=ctypes.windll.kernel32.LocaleNameToLCID(unicode(t),0)
+ buf=ctypes.create_unicode_buffer(1024)
+ #If the original locale didn't have country info (was just language) then make sure we just get language from Windows
+ if '_' not in i:
+ res=ctypes.windll.kernel32.GetLocaleInfoW(LCID,LOCALE_SLANGDISPLAYNAME,buf,1024)
+ else:
+ res=0
+ if res==0:
+ res=ctypes.windll.kernel32.GetLocaleInfoW(LCID,LOCALE_SLANGUAGE,buf,1024)
+ sLanguage=buf.value
+ label="%s, %s"%(sLanguage,i)
+ d.append(label)
+ #include a 'user default, windows' language, which just represents the default language for this user account
  l.append("Windows")
- return l
+ d.append("User default, windows")
+ #return a zipped up version of both the lists (a list with tuples of locale,label)
+ return zip(l,d)
 
 def setLanguage(lang):
  global curLang
  try:
  if lang=="Windows":
- windowsLCID=ctypes.windll.kernel32.GetThreadLocale()
+ windowsLCID=ctypes.windll.kernel32.GetUserDefaultLCID()
  localeName=locale.windows_locale[windowsLCID]
  gettext.translation('nvda',localedir='locale',languages=[localeName]).install(True)
  curLang=localeName


Reply | Threaded
Open this post in threaded view
|

Re: [Nvda-dev] commit r1968 - in trunk/source: . gui

Peter Vágner
Hello,

NVDA Subversion  wrote:
> + LCID=ctypes.windll.kernel32.LocaleNameToLCID(unicode(t),0)

OOps, function LocaleNameToLCID does not appear to be present in Windows
XP and older oses.
Here is a quotation from the MSDN at:
http://msdn2.microsoft.com/en-us/library/ms776388(VS.85).aspx
> Requirements
>   Windows Vista: Included in Windows Vista and later.
>
>   Windows 95/98/Me/NT/2000/XP: Unsupported.

I don't have a fix for it yet.

Peter


Reply | Threaded
Open this post in threaded view
|

Re: [Nvda-dev] commit r1968 - in trunk/source: . gui

Peter Vágner
Hello,

Peter Vágner  wrote:
> OOps, function LocaleNameToLCID does not appear to be present in Windows
> XP and older oses.
> I don't have a fix for it yet.
Sorry to posting a lot but I think we can use MAKELCID for that:
http://msdn2.microsoft.com/en-us/library/ms776310(VS.85).aspx
The problem is I am in a hurry so I can't really try using that atm.

Tonight I might be able to.

Peter