6 from dicoparser import *
8 def normalize( theTranslation ):
9 if '_' in theTranslation:
10 return '__'.join( theTranslation.split( '_' ) )
14 def translate( theDicoFile, theCataFile, theTSFile, theNotTranslatedFile = '' ):
16 SPECIAL = ['into', 'defaut']
17 DICO = DicoParser( theDicoFile, 'NOM', 'NOM1' )
20 def is_ok( theName, theObject ):
21 ok = isinstance( theObject, N_ENTITE.ENTITE ) or theName in SPECIAL
24 def name_to_attr( theName ):
28 return theName.upper()
30 def dico_tr( theObject, theName, theParentObj, theParentName ):
31 #print "dicotr:", theObject, theName, theParentObj, theParentName
33 if theName in SPECIAL:
35 #print theName, theObject
36 anAttrTr = name_to_attr( theName )
37 anAttr = anAttrTr + '1'
38 if isinstance( theObject, basestring ):
39 #print theParentName, theName, theObject, '=>',
40 aTrans = DICO.translate( theParentName, '', theObject, anAttr, anAttrTr )
42 elif isinstance( theObject, tuple ):
43 #print theParentName, theName
44 for anItem in theObject:
46 if isinstance( anItem, basestring ) and '=' in anItem:
47 aList = DICO.convert_to_tuples( DICO.parse_tokens( anItem ) )
49 for aListItem in aList:
50 if isinstance( aListItem, tuple ):
51 aKey, aValue = aListItem
52 #print " ", aValue, '=>',
53 aTrans = DICO.translate( theParentName, '', aValue, anAttr, anAttrTr )
60 aTrans = DICO.translate( theName, 'NOM' )
63 aTrans = normalize( aTrans )
68 if hasattr( theObject, 'entites' ):
69 aDict = copy.copy( theObject.entites );
71 if hasattr( theObject, s ):
72 aDict[s] = getattr( theObject, s )
75 PARSER.check_object = is_ok
76 PARSER.translation = dico_tr
77 PARSER.sub_objects = sub
78 PARSER.parse( theCataFile, theTSFile )
80 if len( theNotTranslatedFile ) > 0:
81 PARSER.saveNotTranslated( theNotTranslatedFile )
84 #print "Translations:"
85 #for key, value in p.data[''].iteritems():
86 # print key, "=>", value