Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Windows OneCore voices included in Windows 10. #7110

Merged
merged 13 commits into from Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions source/languageHandler.py
Expand Up @@ -15,21 +15,31 @@
LOCALE_SLANGUAGE=0x2
LOCALE_SLANGDISPLAYNAME=0x6f
LOCALE_CUSTOM_UNSPECIFIED = 0x1000
#: Returned from L{localeNameToWindowsLCID} when the locale name cannot be mapped to a locale identifier.
#: This might be because Windows doesn't know about the locale (e.g. "an"),
#: because it is not a standardized locale name anywhere (e.g. "zz")
#: or because it is not a legal locale name (e.g. "zzzz").
LCID_NONE = 0 # 0 used instead of None for backwards compatibility.

curLang="en"

def localeNameToWindowsLCID(localeName):
"""Retreave the Windows locale identifier (LCID) for the given locale name
@param localeName: a string of 2letterLanguage_2letterCountry or or just 2letterLanguage
@type localeName: string
@returns: a Windows LCID
@returns: a Windows LCID or L{LCID_NONE} if it could not be retrieved.
@rtype: integer
"""
#Windows Vista is able to convert locale names to LCIDs
func_LocaleNameToLCID=getattr(ctypes.windll.kernel32,'LocaleNameToLCID',None)
if func_LocaleNameToLCID is not None:
localeName=localeName.replace('_','-')
LCID=func_LocaleNameToLCID(unicode(localeName),0)
# #6259: In Windows 10, LOCALE_CUSTOM_UNSPECIFIED is returned for any locale name unknown to Windows.
# This was observed for Aragonese ("an").
# See https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.lcid(v=vs.110).aspx.
if LCID==LOCALE_CUSTOM_UNSPECIFIED:
LCID=LCID_NONE
else: #Windows doesn't have this functionality, manually search Python's windows_locale dictionary for the LCID
localeName=locale.normalize(localeName)
if '.' in localeName:
Expand All @@ -38,7 +48,7 @@ def localeNameToWindowsLCID(localeName):
if len(LCList)>0:
LCID=LCList[0]
else:
LCID=0
LCID=LCID_NONE
return LCID

def windowsLCIDToLocaleName(lcid):
Expand All @@ -58,9 +68,7 @@ def getLanguageDescription(language):
"""Finds out the description (localized full name) of a given local name"""
desc=None
LCID=localeNameToWindowsLCID(language)
# #6259: LOCALE_CUSTOM_UNSPECIFIED denotes custom locale in Windows 10, thus returns "unknown language" or an odd description (observed for Aragonese).
# See https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.lcid(v=vs.110).aspx.
if LCID not in (0, LOCALE_CUSTOM_UNSPECIFIED):
if LCID is not LCID_NONE:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is much clearer

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 language:
Expand Down
2 changes: 1 addition & 1 deletion source/synthDrivers/oneCore.py
Expand Up @@ -86,7 +86,7 @@ def convertCharacterModeCommand(self, command):

def convertLangChangeCommand(self, command):
lcid = languageHandler.localeNameToWindowsLCID(command.lang)
if lcid in (0, languageHandler.LOCALE_CUSTOM_UNSPECIFIED):
if lcid is languageHandler.LCID_NONE:
log.debugWarning("Invalid language: %s" % command.lang)
return None
return super(_OcSsmlConverter, self).convertLangChangeCommand(command)
Expand Down
Empty file.
34 changes: 0 additions & 34 deletions tests/unit/synthDrivers/test_oneCore.py

This file was deleted.

33 changes: 33 additions & 0 deletions tests/unit/test_languageHandler.py
@@ -0,0 +1,33 @@
#tests/unit/test_languageHandler.py
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2017 NV Access Limited

"""Unit tests for the languageHandler module.
"""

import unittest
import languageHandler
from languageHandler import LCID_NONE

LCID_ENGLISH_US = 0x0409

class TestLocaleNameToWindowsLCID(unittest.TestCase):

def test_knownLocale(self):
lcid = languageHandler.localeNameToWindowsLCID("en")
self.assertEqual(lcid, LCID_ENGLISH_US)

def test_windowsUnknownLocale(self):
# "an" is the locale name for Aragonese, but Windows doesn't know about it.
lcid = languageHandler.localeNameToWindowsLCID("an")
self.assertEqual(lcid, LCID_NONE)

def test_nonStandardLocale(self):
lcid = languageHandler.localeNameToWindowsLCID("us")
self.assertEqual(lcid, LCID_NONE)

def test_invalidLocale(self):
lcid = languageHandler.localeNameToWindowsLCID("zzzz")
self.assertEqual(lcid, LCID_NONE)