+import __builtin__\r
import os\r
import sys\r
import ctypes\r
#return a zipped up version of both the lists (a list with tuples of locale,label)\r
return zip(l,d)\r
\r
+def makePgettext(translations):\r
+ if isinstance(translations, gettext.GNUTranslations):\r
+ def pgettext(context, message):\r
+ message = unicode(message)\r
+ try:\r
+ # Look up the message with its context.\r
+ return translations._catalog[u"%s\x04%s" % (context, message)]\r
+ except KeyError:\r
+ return message\r
+ else:\r
+ def pgettext(context, message):\r
+ return unicode(message)\r
+ return pgettext\r
+\r
def setLanguage(lang):\r
global curLang\r
try:\r
if lang=="Windows":\r
windowsLCID=ctypes.windll.kernel32.GetUserDefaultUILanguage()\r
localeName=locale.windows_locale[windowsLCID]\r
- gettext.translation('nvda',localedir='locale',languages=[localeName]).install(True)\r
+ trans=gettext.translation('nvda',localedir='locale',languages=[localeName])\r
curLang=localeName\r
else:\r
- gettext.translation("nvda", localedir="locale", languages=[lang]).install(True)\r
+ trans=gettext.translation("nvda", localedir="locale", languages=[lang])\r
curLang=lang\r
localeChanged=False\r
#Try setting Python's locale to lang\r
#Set the windows locale for this thread (NVDA core) to this locale.\r
LCID=localeNameToWindowsLCID(lang)\r
ctypes.windll.kernel32.SetThreadLocale(LCID)\r
- return True\r
except IOError:\r
- gettext.install("nvda", unicode=True)\r
+ trans=gettext.translation("nvda",fallback=True)\r
curLang="en"\r
- return False\r
+ trans.install(unicode=True)\r
+ # Install our pgettext function.\r
+ __builtin__.__dict__["pgettext"] = makePgettext(trans)\r
\r
def getLanguage():\r
return curLang\r
- Previous log file is now copied to nvda-old.log on NVDA initialization. Therefore, if NVDA crashes or is restarted, logging information from that session is still accessible for inspection. (#916)\r
- Fetching the role property in chooseNVDAObjectOverlayClasses no longer causes the role to be incorrect and thus not reported on focus for certain objects such as Windows command consoles and Scintilla controls. (#2569)\r
- The NVDA Preferences, Tools and Help menus are now accessible as attributes on gui.mainFrame.sysTrayIcon named preferencesMenu, toolsMenu and helpMenu, respectively. This allows plugins to more easily add items to these menus.\r
+- Gettext message contexts are now supported. This allows multiple translations to be defined for a single English message depending on the context. (#1524)\r
+ - This is done using the pgettext(context, message) function.\r
+ - This is supported for both NVDA itself and add-ons.\r
+ - xgettext and msgfmt from GNU gettext must be used to create any PO and MO files. The Python tools do not support message contexts.\r
+ - For xgettext, pass the --keyword=pgettext:1c,2 command line argument to enable inclusion of message contexts.\r
+ - See http://www.gnu.org/software/gettext/manual/html_node/Contexts.html#Contexts for more information.\r
\r
\r
= 2012.2.1 =\r