6 from dicoparser import *
8 def normalize( theTranslation ):
9 aTranslation = theTranslation
10 if '_' in aTranslation:
11 aTranslation = '__'.join( aTranslation.split( '_' ) )
13 aTranslation = aTranslation.replace( ' ', '_' )
16 def translate( theDicoFile, theCataFile, theTSFile, theNotTranslatedFile = '' ):
18 SPECIAL = ['into', 'defaut']
19 DICO = DicoParser( theDicoFile, 'NOM', 'NOM1' )
22 def is_ok( theName, theObject ):
23 ok = isinstance( theObject, N_ENTITE.ENTITE ) or theName in SPECIAL
26 def name_to_attr( theName ):
30 return theName.upper()
32 def dico_tr( theObject, theName, theParentObj, theParentName ):
33 #print "dicotr:", theObject, theName, theParentObj, theParentName
35 if theName in SPECIAL:
37 #print theName, theObject
38 anAttrTr = name_to_attr( theName )
39 anAttr = anAttrTr + '1'
40 if isinstance( theObject, basestring ):
41 #print theParentName, theName, theObject, '=>',
42 aTrans = DICO.translate( theParentName, '', theObject, anAttr, anAttrTr )
44 elif isinstance( theObject, tuple ):
45 #print theParentName, theName
46 for anItem in theObject:
48 if isinstance( anItem, basestring ) and '=' in anItem:
49 aList = DICO.convert_to_tuples( DICO.parse_tokens( anItem ) )
51 for aListItem in aList:
52 if isinstance( aListItem, tuple ):
53 aKey, aValue = aListItem
54 #print " ", aValue, '=>',
55 aTrans = DICO.translate( theParentName, '', aValue, anAttr, anAttrTr )
62 aTrans = DICO.translate( theName, 'NOM' )
65 aTrans = normalize( aTrans )
70 if hasattr( theObject, 'entites' ):
71 aDict = copy.copy( theObject.entites );
73 if hasattr( theObject, s ):
74 aDict[s] = getattr( theObject, s )
77 PARSER.check_object = is_ok
78 PARSER.translation = dico_tr
79 PARSER.sub_objects = sub
80 PARSER.parse( theCataFile, theTSFile )
82 if len( theNotTranslatedFile ) > 0:
83 PARSER.saveNotTranslated( theNotTranslatedFile )
86 #print "Translations:"
87 #for key, value in p.data[''].iteritems():
88 # print key, "=>", value