# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: manish10@gmail.com-20130312152034-douyv1k4ewi0gy7c
# target_branch: http://bzr.nvaccess.org/nvda/main/
# testament_sha1: 677aa077138a45c0eb2d5b1893f0fa636cacad2d
# timestamp: 2013-03-12 20:51:55 +0530
# base_revision_id: jamie@jantrid.net-20130309060423-1j1t0jp3jvu4otud
# 
# Begin patch
=== modified file 'nvdaHelper/remote/winword.cpp'
--- nvdaHelper/remote/winword.cpp	2013-02-01 04:54:31 +0000
+++ nvdaHelper/remote/winword.cpp	2013-03-12 15:20:34 +0000
@@ -46,6 +46,8 @@
 #define wdDISPID_RANGE_END 4
 #define wdDISPID_RANGE_INFORMATION 313
 #define wdDISPID_RANGE_STYLE 151
+#define wdDISPID_RANGE_LANGUAGEID 153
+#define wdDISPID_RANGE_LanguageIDFarEast 321
 #define wdDISPID_STYLE_NAMELOCAL 0
 #define wdDISPID_RANGE_SPELLINGERRORS 316
 #define wdDISPID_SPELLINGERRORS_COUNT 1
@@ -117,6 +119,9 @@
 #define wdAlignParagraphCenter 1
 #define wdAlignParagraphRight 2
 #define wdAlignParagraphJustify 3
+#define wdLanguageNone 0  //&H0
+#define wdNoProofing 1024  //&H400
+#define wdLanguageUnknown 9999999
 
 #define formatConfig_reportFontName 1
 #define formatConfig_reportFontSize 2
@@ -132,10 +137,11 @@
 #define formatConfig_reportLinks 2048
 #define formatConfig_reportComments 4096
 #define formatConfig_reportHeadings 8192
+#define formatConfig_reportLanguage 16384
 
 #define formatConfig_fontFlags (formatConfig_reportFontName|formatConfig_reportFontSize|formatConfig_reportFontAttributes|formatConfig_reportColor)
 #define formatConfig_initialFormatFlags (formatConfig_reportPage|formatConfig_reportLineNumber|formatConfig_reportTables|formatConfig_reportHeadings)
- 
+
 UINT wm_winword_expandToLine=0;
 typedef struct {
 	int offset;
@@ -400,7 +406,21 @@
 				formatAttribsStream<<L"invalid-spelling=\""<<iVal<<L"\" ";
 			}
 		}
-	} 
+	}
+	if (formatConfig&formatConfig_reportLanguage) {
+		int languageId = 0;
+		int languageIdFarEast = 0;
+		if (_com_dispatch_raw_propget(pDispatchRange,	wdDISPID_RANGE_LANGUAGEID, VT_I4, &languageId)==S_OK) {
+			if (languageId != wdLanguageNone && languageId != wdNoProofing && languageId != wdLanguageUnknown) {
+				formatAttribsStream<<L"wdLanguageId=\""<<languageId<<L"\" ";
+			}
+		}
+		if (_com_dispatch_raw_propget(pDispatchRange,	wdDISPID_RANGE_LanguageIDFarEast, VT_I4, &languageIdFarEast)==S_OK) {
+			if (languageIdFarEast != wdLanguageNone && languageIdFarEast != wdNoProofing && languageIdFarEast != wdLanguageUnknown) {
+				formatAttribsStream<<L"wdLanguageIdFarEast=\""<<languageIdFarEast<<L"\" ";
+			}
+		}
+	}
 }
 
 inline int getInlineShapesCount(IDispatch* pDispatchRange) {

=== modified file 'source/NVDAObjects/window/winword.py'
--- source/NVDAObjects/window/winword.py	2012-07-18 04:58:51 +0000
+++ source/NVDAObjects/window/winword.py	2013-03-12 15:20:34 +0000
@@ -8,6 +8,8 @@
 from comtypes import COMError, GUID, BSTR
 import comtypes.client
 import comtypes.automation
+import locale
+import languageHandler
 import ui
 import NVDAHelper
 import XMLFormatting
@@ -124,6 +126,17 @@
 	"reportLinks":2048,
 	"reportComments":4096,
 	"reportHeadings":8192,
+	"autoLanguageSwitching":16384,	
+}
+
+AllFarEastLanguages ={
+	3076, # wdChineseHongKongSAR
+	5124, # wdChineseMacaoSAR
+	2052, #wdSimplifiedChinese
+	4100, #wdChineseSingapore
+	1028, #wdTraditionalChinese
+	1041, # wdJapanese
+	1042, # wdKorean
 }
 
 class WordDocumentTextInfo(textInfos.TextInfo):
@@ -172,6 +185,7 @@
 	def getTextWithFields(self,formatConfig=None):
 		if not formatConfig:
 			formatConfig=config.conf['documentFormatting']
+		formatConfig['autoLanguageSwitching']=config.conf['speech'].get('autoLanguageSwitching',False)
 		startOffset=self._rangeObj.start
 		endOffset=self._rangeObj.end
 		if startOffset==endOffset:
@@ -227,9 +241,27 @@
 	def _normalizeFormatField(self,field):
 		color=field.pop('color',None)
 		if color is not None:
-			field['color']=colors.RGB.fromCOLORREF(int(color))
+			field['color']=colors.RGB.fromCOLORREF(int(color))		
+		try:
+			languageIdFarEast = int(field.pop('wdLanguageIdFarEast',0))
+			if languageIdFarEast and languageIdFarEast in AllFarEastLanguages:
+				field['language']=_getLanguageFromLcid(languageIdFarEast)
+			else:
+				languageId = int(field.pop('wdLanguageId',0))
+				if languageId:
+					field['language']=self._getLanguageFromLcid(languageId)
+		except:
+			pass			
 		return field
 
+	def _getLanguageFromLcid(self, lcid):
+		"""
+		gets a normalized locale from a lcid
+		"""
+		lang = locale.windows_locale[lcid]
+		if lang:
+			return languageHandler.normalizeLanguage(lang)
+		
 	def expand(self,unit):
 		if unit==textInfos.UNIT_LINE and self.basePosition not in (textInfos.POSITION_CARET,textInfos.POSITION_SELECTION):
 			unit=textInfos.UNIT_SENTENCE

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWcGhCNkAA5TfgGgye+f//3//
3w6////6YAhc6L73bXG2NSrbYdzaNNCqru5xRxkyaNAaNMRkaGIYE0aYgxGgwgAMEoggDTSYUMmo
9J4p5QNDQBo0PUaAGgaAlCaARNNTUeyqNp6T00o2k0D1AA0BoBo0NM0EiJGhTahqjemQyZTQB6mp
6IZGjIwmnqMBoEHGTJo0Bo0xGRoYhgTRpiDEaDCAAwSRI0FPEA1T0YR6k8miZoaU9J6aJkYmAhoD
yki0sQWC97Eb8wm2wY200xjayshA0m0iBqG70uBgmxDaWp8b04csobTZ7Ppd+BwrCSwboUgiw47e
OQIUMqs03hlKPG87rK9ZR6fUYwOBwuuRHpjVT/vPWaaLD1LyWxEnTs+HBlxwK5no+8tyWzdl+Tbe
+a0vXc3B61izsFpZyG4NtIby989oslmDMlDkk67WvLWdk1fi3bJo3xTLM443LJxdmSDCXFld7zU3
i7fDHQ0/x5E866N1en1f74olK94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