2 # This file is used to collect all defined strings in multiple uni files
4 # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 import Common
.LongFilePathOs
as os
, codecs
, re
18 import Common
.EdkLogger
as EdkLogger
19 from Common
.BuildToolError
import *
20 from Common
.String
import GetLineNo
21 from Common
.Misc
import PathClass
22 from Common
.LongFilePathSupport
import LongFilePath
26 UNICODE_WIDE_CHAR
= u
'\\wide'
27 UNICODE_NARROW_CHAR
= u
'\\narrow'
28 UNICODE_NON_BREAKING_CHAR
= u
'\\nbr'
29 UNICODE_UNICODE_CR
= '\r'
30 UNICODE_UNICODE_LF
= '\n'
32 NARROW_CHAR
= u
'\uFFF0'
34 NON_BREAKING_CHAR
= u
'\uFFF2'
40 DOBULE_QUOTED_SPLASH
= u
'\\"'
41 SIGLE_QUOTED_SPLASH
= u
"\\'"
42 TAB_BACK_SLASH
= u
"\\/"
44 gIncludePattern
= re
.compile("^#include +[\"<]+([^\"< >]+)[>\"]+$", re
.MULTILINE | re
.UNICODE
)
46 ## Convert a python unicode string to a normal string
48 # Convert a python unicode string to a normal string
49 # UniToStr(u'I am a string') is 'I am a string'
51 # @param Uni: The python unicode string
53 # @retval: The formatted normal string
56 return repr(Uni
)[2:-1]
58 ## Convert a unicode string to a Hex list
60 # Convert a unicode string to a Hex list
61 # UniToHexList('ABC') is ['0x41', '0x00', '0x42', '0x00', '0x43', '0x00']
63 # @param Uni: The python unicode string
65 # @retval List: The formatted hex list
67 def UniToHexList(Uni
):
70 Temp
= '%04X' % ord(Item
)
71 List
.append('0x' + Temp
[2:4])
72 List
.append('0x' + Temp
[0:2])
75 LangConvTable
= {'eng':'en', 'fra':'fr', \
76 'aar':'aa', 'abk':'ab', 'ave':'ae', 'afr':'af', 'aka':'ak', 'amh':'am', \
77 'arg':'an', 'ara':'ar', 'asm':'as', 'ava':'av', 'aym':'ay', 'aze':'az', \
78 'bak':'ba', 'bel':'be', 'bul':'bg', 'bih':'bh', 'bis':'bi', 'bam':'bm', \
79 'ben':'bn', 'bod':'bo', 'bre':'br', 'bos':'bs', 'cat':'ca', 'che':'ce', \
80 'cha':'ch', 'cos':'co', 'cre':'cr', 'ces':'cs', 'chu':'cu', 'chv':'cv', \
81 'cym':'cy', 'dan':'da', 'deu':'de', 'div':'dv', 'dzo':'dz', 'ewe':'ee', \
82 'ell':'el', 'epo':'eo', 'spa':'es', 'est':'et', 'eus':'eu', 'fas':'fa', \
83 'ful':'ff', 'fin':'fi', 'fij':'fj', 'fao':'fo', 'fry':'fy', 'gle':'ga', \
84 'gla':'gd', 'glg':'gl', 'grn':'gn', 'guj':'gu', 'glv':'gv', 'hau':'ha', \
85 'heb':'he', 'hin':'hi', 'hmo':'ho', 'hrv':'hr', 'hat':'ht', 'hun':'hu', \
86 'hye':'hy', 'her':'hz', 'ina':'ia', 'ind':'id', 'ile':'ie', 'ibo':'ig', \
87 'iii':'ii', 'ipk':'ik', 'ido':'io', 'isl':'is', 'ita':'it', 'iku':'iu', \
88 'jpn':'ja', 'jav':'jv', 'kat':'ka', 'kon':'kg', 'kik':'ki', 'kua':'kj', \
89 'kaz':'kk', 'kal':'kl', 'khm':'km', 'kan':'kn', 'kor':'ko', 'kau':'kr', \
90 'kas':'ks', 'kur':'ku', 'kom':'kv', 'cor':'kw', 'kir':'ky', 'lat':'la', \
91 'ltz':'lb', 'lug':'lg', 'lim':'li', 'lin':'ln', 'lao':'lo', 'lit':'lt', \
92 'lub':'lu', 'lav':'lv', 'mlg':'mg', 'mah':'mh', 'mri':'mi', 'mkd':'mk', \
93 'mal':'ml', 'mon':'mn', 'mar':'mr', 'msa':'ms', 'mlt':'mt', 'mya':'my', \
94 'nau':'na', 'nob':'nb', 'nde':'nd', 'nep':'ne', 'ndo':'ng', 'nld':'nl', \
95 'nno':'nn', 'nor':'no', 'nbl':'nr', 'nav':'nv', 'nya':'ny', 'oci':'oc', \
96 'oji':'oj', 'orm':'om', 'ori':'or', 'oss':'os', 'pan':'pa', 'pli':'pi', \
97 'pol':'pl', 'pus':'ps', 'por':'pt', 'que':'qu', 'roh':'rm', 'run':'rn', \
98 'ron':'ro', 'rus':'ru', 'kin':'rw', 'san':'sa', 'srd':'sc', 'snd':'sd', \
99 'sme':'se', 'sag':'sg', 'sin':'si', 'slk':'sk', 'slv':'sl', 'smo':'sm', \
100 'sna':'sn', 'som':'so', 'sqi':'sq', 'srp':'sr', 'ssw':'ss', 'sot':'st', \
101 'sun':'su', 'swe':'sv', 'swa':'sw', 'tam':'ta', 'tel':'te', 'tgk':'tg', \
102 'tha':'th', 'tir':'ti', 'tuk':'tk', 'tgl':'tl', 'tsn':'tn', 'ton':'to', \
103 'tur':'tr', 'tso':'ts', 'tat':'tt', 'twi':'tw', 'tah':'ty', 'uig':'ug', \
104 'ukr':'uk', 'urd':'ur', 'uzb':'uz', 'ven':'ve', 'vie':'vi', 'vol':'vo', \
105 'wln':'wa', 'wol':'wo', 'xho':'xh', 'yid':'yi', 'yor':'yo', 'zha':'za', \
106 'zho':'zh', 'zul':'zu'}
110 # Check the language code read from .UNI file and convert ISO 639-2 codes to RFC 4646 codes if appropriate
111 # ISO 639-2 language codes supported in compatiblity mode
112 # RFC 4646 language codes supported in native mode
114 # @param LangName: Language codes read from .UNI file
116 # @retval LangName: Valid lanugage code in RFC 4646 format or None
118 def GetLanguageCode(LangName
, IsCompatibleMode
, File
):
121 length
= len(LangName
)
123 if length
== 3 and LangName
.isalpha():
124 TempLangName
= LangConvTable
.get(LangName
.lower())
125 if TempLangName
!= None:
129 EdkLogger
.error("Unicode File Parser", FORMAT_INVALID
, "Invalid ISO 639-2 language code : %s" % LangName
, File
)
131 if (LangName
[0] == 'X' or LangName
[0] == 'x') and LangName
[1] == '-':
134 if LangName
.isalpha():
137 if LangName
.isalpha() and LangConvTable
.get(LangName
.lower()) == None:
140 if LangName
[0:2].isalpha() and LangName
[2] == '-':
143 if LangName
[0:2].isalpha() and LangName
[2] == '-':
145 if LangName
[0:3].isalpha() and LangConvTable
.get(LangName
.lower()) == None and LangName
[3] == '-':
148 EdkLogger
.error("Unicode File Parser", FORMAT_INVALID
, "Invalid RFC 4646 language code : %s" % LangName
, File
)
150 ## StringDefClassObject
152 # A structure for language definition
154 class StringDefClassObject(object):
155 def __init__(self
, Name
= None, Value
= None, Referenced
= False, Token
= None, UseOtherLangDef
= ''):
157 self
.StringNameByteList
= []
158 self
.StringValue
= ''
159 self
.StringValueByteList
= ''
161 self
.Referenced
= Referenced
162 self
.UseOtherLangDef
= UseOtherLangDef
166 self
.StringName
= Name
167 self
.StringNameByteList
= UniToHexList(Name
)
169 self
.StringValue
= Value
+ u
'\x00' # Add a NULL at string tail
170 self
.StringValueByteList
= UniToHexList(self
.StringValue
)
171 self
.Length
= len(self
.StringValueByteList
)
176 return repr(self
.StringName
) + ' ' + \
177 repr(self
.Token
) + ' ' + \
178 repr(self
.Referenced
) + ' ' + \
179 repr(self
.StringValue
) + ' ' + \
180 repr(self
.UseOtherLangDef
)
182 def UpdateValue(self
, Value
= None):
184 self
.StringValue
= Value
+ u
'\x00' # Add a NULL at string tail
185 self
.StringValueByteList
= UniToHexList(self
.StringValue
)
186 self
.Length
= len(self
.StringValueByteList
)
188 ## UniFileClassObject
190 # A structure for .uni file definition
192 class UniFileClassObject(object):
193 def __init__(self
, FileList
= [], IsCompatibleMode
= False, IncludePathList
= []):
194 self
.FileList
= FileList
196 self
.LanguageDef
= [] #[ [u'LanguageIdentifier', u'PrintableName'], ... ]
197 self
.OrderedStringList
= {} #{ u'LanguageIdentifier' : [StringDefClassObject] }
198 self
.OrderedStringDict
= {} #{ u'LanguageIdentifier' : {StringName:(IndexInList)} }
199 self
.OrderedStringListByToken
= {} #{ u'LanguageIdentifier' : {Token: StringDefClassObject} }
200 self
.IsCompatibleMode
= IsCompatibleMode
201 self
.IncludePathList
= IncludePathList
202 if len(self
.FileList
) > 0:
203 self
.LoadUniFiles(FileList
)
206 # Get Language definition
208 def GetLangDef(self
, File
, Line
):
209 Lang
= distutils
.util
.split_quoted((Line
.split(u
"//")[0]))
212 FileIn
= codecs
.open(LongFilePath(File
.Path
), mode
='rb', encoding
='utf-16').read()
213 except UnicodeError, X
:
214 EdkLogger
.error("build", FILE_READ_FAILURE
, "File read failure: %s" % str(X
), ExtraData
=File
);
216 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=File
);
217 LineNo
= GetLineNo(FileIn
, Line
, False)
218 EdkLogger
.error("Unicode File Parser", PARSER_ERROR
, "Wrong language definition",
219 ExtraData
="""%s\n\t*Correct format is like '#langdef en-US "English"'""" % Line
, File
= File
, Line
= LineNo
)
221 LangName
= GetLanguageCode(Lang
[1], self
.IsCompatibleMode
, self
.File
)
222 LangPrintName
= Lang
[2]
225 for Item
in self
.LanguageDef
:
226 if Item
[0] == LangName
:
231 self
.LanguageDef
.append([LangName
, LangPrintName
])
234 # Add language string
236 self
.AddStringToList(u
'$LANGUAGE_NAME', LangName
, LangName
, 0, True, Index
=0)
237 self
.AddStringToList(u
'$PRINTABLE_LANGUAGE_NAME', LangName
, LangPrintName
, 1, True, Index
=1)
241 # The found STRING tokens will be added into new language string list
242 # so that the unique STRING identifier is reserved for all languages in the package list.
244 FirstLangName
= self
.LanguageDef
[0][0]
245 if LangName
!= FirstLangName
:
246 for Index
in range (2, len (self
.OrderedStringList
[FirstLangName
])):
247 Item
= self
.OrderedStringList
[FirstLangName
][Index
]
248 if Item
.UseOtherLangDef
!= '':
249 OtherLang
= Item
.UseOtherLangDef
251 OtherLang
= FirstLangName
252 self
.OrderedStringList
[LangName
].append (StringDefClassObject(Item
.StringName
, '', Item
.Referenced
, Item
.Token
, OtherLang
))
253 self
.OrderedStringDict
[LangName
][Item
.StringName
] = len(self
.OrderedStringList
[LangName
]) - 1
257 # Get String name and value
259 def GetStringObject(self
, Item
):
263 Name
= Item
.split()[1]
264 # Check the string name is the upper character
266 MatchString
= re
.match('[A-Z0-9_]+', Name
, re
.UNICODE
)
267 if MatchString
== None or MatchString
.end(0) != len(Name
):
268 EdkLogger
.error('Unicode File Parser', FORMAT_INVALID
, 'The string token name %s defined in UNI file %s contains the invalid lower case character.' %(Name
, self
.File
))
269 LanguageList
= Item
.split(u
'#language ')
270 for IndexI
in range(len(LanguageList
)):
274 Language
= LanguageList
[IndexI
].split()[0]
275 Value
= LanguageList
[IndexI
][LanguageList
[IndexI
].find(u
'\"') + len(u
'\"') : LanguageList
[IndexI
].rfind(u
'\"')] #.replace(u'\r\n', u'')
276 Language
= GetLanguageCode(Language
, self
.IsCompatibleMode
, self
.File
)
277 self
.AddStringToList(Name
, Language
, Value
)
280 # Get include file list and load them
282 def GetIncludeFile(self
, Item
, Dir
):
283 FileName
= Item
[Item
.find(u
'#include ') + len(u
'#include ') :Item
.find(u
' ', len(u
'#include '))][1:-1]
284 self
.LoadUniFile(FileName
)
287 # Pre-process before parse .uni file
289 def PreProcess(self
, File
):
290 if not os
.path
.exists(File
.Path
) or not os
.path
.isfile(File
.Path
):
291 EdkLogger
.error("Unicode File Parser", FILE_NOT_FOUND
, ExtraData
=File
.Path
)
294 FileIn
= codecs
.open(LongFilePath(File
.Path
), mode
='rb', encoding
='utf-16').readlines()
295 except UnicodeError, X
:
296 EdkLogger
.error("build", FILE_READ_FAILURE
, "File read failure: %s" % str(X
), ExtraData
=File
.Path
);
298 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=File
.Path
);
302 # Use unique identifier
307 Line
= FileIn
[LineCount
]
311 # Ignore comment line and empty line
313 if Line
== u
'' or Line
.startswith(u
'//'):
317 # Process comment embeded in string define lines
319 FindFlag
= Line
.find(u
'//')
321 Line
= Line
.replace(Line
[FindFlag
:], u
' ')
322 if FileIn
[LineCount
].strip().startswith('#language'):
323 Line
= Line
+ FileIn
[LineCount
]
324 FileIn
[LineCount
-1] = Line
325 FileIn
[LineCount
] = os
.linesep
327 for Index
in xrange (LineCount
+ 1, len (FileIn
) - 1):
328 if (Index
== len(FileIn
) -1):
329 FileIn
[Index
] = os
.linesep
331 FileIn
[Index
] = FileIn
[Index
+ 1]
334 Line
= Line
.replace(u
'/langdef', u
'#langdef')
335 Line
= Line
.replace(u
'/string', u
'#string')
336 Line
= Line
.replace(u
'/language', u
'#language')
337 Line
= Line
.replace(u
'/include', u
'#include')
339 Line
= Line
.replace(u
'\\\\', u
'\u0006')
340 Line
= Line
.replace(UNICODE_WIDE_CHAR
, WIDE_CHAR
)
341 Line
= Line
.replace(UNICODE_NARROW_CHAR
, NARROW_CHAR
)
342 Line
= Line
.replace(UNICODE_NON_BREAKING_CHAR
, NON_BREAKING_CHAR
)
344 Line
= Line
.replace(u
'\\r\\n', CR
+ LF
)
345 Line
= Line
.replace(u
'\\n', CR
+ LF
)
346 Line
= Line
.replace(u
'\\r', CR
)
347 Line
= Line
.replace(u
'\\t', u
'\t')
348 Line
= Line
.replace(u
'''\"''', u
'''"''')
349 Line
= Line
.replace(u
'\t', u
' ')
350 Line
= Line
.replace(u
'\u0006', u
'\\')
351 Line
= Line
.replace(DOBULE_QUOTED_SPLASH
, u
'"')
352 Line
= Line
.replace(SIGLE_QUOTED_SPLASH
, u
"'")
353 Line
= Line
.replace(TAB_BACK_SLASH
, u
"/")
355 # if Line.find(u'\\x'):
356 # hex = Line[Line.find(u'\\x') + 2 : Line.find(u'\\x') + 6]
357 # hex = "u'\\u" + hex + "'"
359 IncList
= gIncludePattern
.findall(Line
)
360 if len(IncList
) == 1:
361 for Dir
in [File
.Dir
] + self
.IncludePathList
:
362 IncFile
= PathClass(str(IncList
[0]), Dir
)
363 if os
.path
.isfile(IncFile
.Path
):
364 Lines
.extend(self
.PreProcess(IncFile
))
367 EdkLogger
.error("Unicode File Parser", FILE_NOT_FOUND
, Message
="Cannot find include file", ExtraData
=str(IncList
[0]))
377 def LoadUniFile(self
, File
= None):
379 EdkLogger
.error("Unicode File Parser", PARSER_ERROR
, 'No unicode file is given')
382 # Process special char in file
384 Lines
= self
.PreProcess(File
)
387 # Get Unicode Information
389 for IndexI
in range(len(Lines
)):
391 if (IndexI
+ 1) < len(Lines
):
392 SecondLine
= Lines
[IndexI
+ 1]
393 if (IndexI
+ 2) < len(Lines
):
394 ThirdLine
= Lines
[IndexI
+ 2]
397 # Get Language def information
399 if Line
.find(u
'#langdef ') >= 0:
400 self
.GetLangDef(File
, Line
)
407 # Get string def information format 1 as below
409 # #string MY_STRING_1
411 # My first English string line 1
412 # My first English string line 2
413 # #string MY_STRING_1
415 # Mi segunda secuencia 1
416 # Mi segunda secuencia 2
418 if Line
.find(u
'#string ') >= 0 and Line
.find(u
'#language ') < 0 and \
419 SecondLine
.find(u
'#string ') < 0 and SecondLine
.find(u
'#language ') >= 0 and \
420 ThirdLine
.find(u
'#string ') < 0 and ThirdLine
.find(u
'#language ') < 0:
421 Name
= Line
[Line
.find(u
'#string ') + len(u
'#string ') : ].strip(' ')
422 Language
= SecondLine
[SecondLine
.find(u
'#language ') + len(u
'#language ') : ].strip(' ')
423 for IndexJ
in range(IndexI
+ 2, len(Lines
)):
424 if Lines
[IndexJ
].find(u
'#string ') < 0 and Lines
[IndexJ
].find(u
'#language ') < 0:
425 Value
= Value
+ Lines
[IndexJ
]
429 # Value = Value.replace(u'\r\n', u'')
430 Language
= GetLanguageCode(Language
, self
.IsCompatibleMode
, self
.File
)
431 # Check the string name is the upper character
432 if not self
.IsCompatibleMode
and Name
!= '':
433 MatchString
= re
.match('[A-Z0-9_]+', Name
, re
.UNICODE
)
434 if MatchString
== None or MatchString
.end(0) != len(Name
):
435 EdkLogger
.error('Unicode File Parser', FORMAT_INVALID
, 'The string token name %s defined in UNI file %s contains the invalid lower case character.' %(Name
, self
.File
))
436 self
.AddStringToList(Name
, Language
, Value
)
440 # Get string def information format 2 as below
442 # #string MY_STRING_1 #language eng "My first English string line 1"
443 # "My first English string line 2"
444 # #language spa "Mi segunda secuencia 1"
445 # "Mi segunda secuencia 2"
446 # #string MY_STRING_2 #language eng "My first English string line 1"
447 # "My first English string line 2"
448 # #string MY_STRING_2 #language spa "Mi segunda secuencia 1"
449 # "Mi segunda secuencia 2"
451 if Line
.find(u
'#string ') >= 0 and Line
.find(u
'#language ') >= 0:
453 for IndexJ
in range(IndexI
+ 1, len(Lines
)):
454 if Lines
[IndexJ
].find(u
'#string ') >= 0 and Lines
[IndexJ
].find(u
'#language ') >= 0:
457 elif Lines
[IndexJ
].find(u
'#string ') < 0 and Lines
[IndexJ
].find(u
'#language ') >= 0:
458 StringItem
= StringItem
+ Lines
[IndexJ
]
459 elif Lines
[IndexJ
].count(u
'\"') >= 2:
460 StringItem
= StringItem
[ : StringItem
.rfind(u
'\"')] + Lines
[IndexJ
][Lines
[IndexJ
].find(u
'\"') + len(u
'\"') : ]
461 self
.GetStringObject(StringItem
)
465 # Load multiple .uni files
467 def LoadUniFiles(self
, FileList
):
468 if len(FileList
) > 0:
469 for File
in FileList
:
470 self
.LoadUniFile(File
)
473 # Add a string to list
475 def AddStringToList(self
, Name
, Language
, Value
, Token
= None, Referenced
= False, UseOtherLangDef
= '', Index
= -1):
476 for LangNameItem
in self
.LanguageDef
:
477 if Language
== LangNameItem
[0]:
480 EdkLogger
.error('Unicode File Parser', FORMAT_NOT_SUPPORTED
, "The language '%s' for %s is not defined in Unicode file %s." \
481 % (Language
, Name
, self
.File
))
483 if Language
not in self
.OrderedStringList
:
484 self
.OrderedStringList
[Language
] = []
485 self
.OrderedStringDict
[Language
] = {}
488 if Name
in self
.OrderedStringDict
[Language
]:
491 ItemIndexInList
= self
.OrderedStringDict
[Language
][Name
]
492 Item
= self
.OrderedStringList
[Language
][ItemIndexInList
]
493 Item
.UpdateValue(Value
)
494 Item
.UseOtherLangDef
= ''
497 Token
= len(self
.OrderedStringList
[Language
])
499 self
.OrderedStringList
[Language
].append(StringDefClassObject(Name
, Value
, Referenced
, Token
, UseOtherLangDef
))
500 self
.OrderedStringDict
[Language
][Name
] = Token
501 for LangName
in self
.LanguageDef
:
503 # New STRING token will be added into all language string lists.
504 # so that the unique STRING identifier is reserved for all languages in the package list.
506 if LangName
[0] != Language
:
507 if UseOtherLangDef
!= '':
508 OtherLangDef
= UseOtherLangDef
510 OtherLangDef
= Language
511 self
.OrderedStringList
[LangName
[0]].append(StringDefClassObject(Name
, '', Referenced
, Token
, OtherLangDef
))
512 self
.OrderedStringDict
[LangName
[0]][Name
] = len(self
.OrderedStringList
[LangName
[0]]) - 1
514 self
.OrderedStringList
[Language
].insert(Index
, StringDefClassObject(Name
, Value
, Referenced
, Token
, UseOtherLangDef
))
515 self
.OrderedStringDict
[Language
][Name
] = Index
518 # Set the string as referenced
520 def SetStringReferenced(self
, Name
):
522 # String stoken are added in the same order in all language string lists.
523 # So, only update the status of string stoken in first language string list.
525 Lang
= self
.LanguageDef
[0][0]
526 if Name
in self
.OrderedStringDict
[Lang
]:
527 ItemIndexInList
= self
.OrderedStringDict
[Lang
][Name
]
528 Item
= self
.OrderedStringList
[Lang
][ItemIndexInList
]
529 Item
.Referenced
= True
532 # Search the string in language definition by Name
534 def FindStringValue(self
, Name
, Lang
):
535 if Name
in self
.OrderedStringDict
[Lang
]:
536 ItemIndexInList
= self
.OrderedStringDict
[Lang
][Name
]
537 return self
.OrderedStringList
[Lang
][ItemIndexInList
]
542 # Search the string in language definition by Token
544 def FindByToken(self
, Token
, Lang
):
545 for Item
in self
.OrderedStringList
[Lang
]:
546 if Item
.Token
== Token
:
552 # Re-order strings and re-generate tokens
556 # Retoken all language strings according to the status of string stoken in the first language string.
558 FirstLangName
= self
.LanguageDef
[0][0]
560 # Convert the OrderedStringList to be OrderedStringListByToken in order to faciliate future search by token
561 for LangNameItem
in self
.LanguageDef
:
562 self
.OrderedStringListByToken
[LangNameItem
[0]] = {}
565 # Use small token for all referred string stoken.
568 for Index
in range (0, len (self
.OrderedStringList
[FirstLangName
])):
569 FirstLangItem
= self
.OrderedStringList
[FirstLangName
][Index
]
570 if FirstLangItem
.Referenced
== True:
571 for LangNameItem
in self
.LanguageDef
:
572 LangName
= LangNameItem
[0]
573 OtherLangItem
= self
.OrderedStringList
[LangName
][Index
]
574 OtherLangItem
.Referenced
= True
575 OtherLangItem
.Token
= RefToken
576 self
.OrderedStringListByToken
[LangName
][OtherLangItem
.Token
] = OtherLangItem
577 RefToken
= RefToken
+ 1
580 # Use big token for all unreferred string stoken.
583 for Index
in range (0, len (self
.OrderedStringList
[FirstLangName
])):
584 FirstLangItem
= self
.OrderedStringList
[FirstLangName
][Index
]
585 if FirstLangItem
.Referenced
== False:
586 for LangNameItem
in self
.LanguageDef
:
587 LangName
= LangNameItem
[0]
588 OtherLangItem
= self
.OrderedStringList
[LangName
][Index
]
589 OtherLangItem
.Token
= RefToken
+ UnRefToken
590 self
.OrderedStringListByToken
[LangName
][OtherLangItem
.Token
] = OtherLangItem
591 UnRefToken
= UnRefToken
+ 1
594 # Show the instance itself
597 print self
.LanguageDef
598 #print self.OrderedStringList
599 for Item
in self
.OrderedStringList
:
601 for Member
in self
.OrderedStringList
[Item
]:
604 # This acts like the main() function for the script, unless it is 'import'ed into another
606 if __name__
== '__main__':
607 EdkLogger
.Initialize()
608 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)
609 a
= UniFileClassObject([PathClass("C:\\Edk\\Strings.uni"), PathClass("C:\\Edk\\Strings2.uni")])