1
2 from elisa.core.tests import component_test_case
3
4 from elisa.plugins.good.xmlmenu.xmltreemenu_activity import XmltreemenuActivity
5 from elisa.core.tests.elisa_test_case import BoilerPlateApp, DEFAULT_CONFIG
6 from elisa.extern.coherence.et import parse_xml
7
8 from elisa.core import common
9
10 import os
11
61
63
64 xml_file = os.path.join(self.directory,
65 '..',
66 'data',
67 'default_menu.xml')
68 reader = open(xml_file,'r')
69
70 data = '<Root>'
71
72 for line in reader:
73 line = line.strip()
74 if line.startswith('<Label'):
75 data += '\n%s\t' % line
76
77 data += '\n</Root>'
78
79 xml = parse_xml(data)
80 root = xml.getroot()
81
82 translator = common.application.translator
83
84 strings_by_domain = {}
85
86 for label in root.findall('Label'):
87 string = label.text
88 domain = label.get('translate-domain', None)
89 if domain:
90 if not strings_by_domain.has_key(domain):
91 strings_by_domain[domain] = []
92 already_found = strings_by_domain[domain]
93 if string not in already_found:
94 already_found.append(string)
95 else:
96 self.fail("'%s' is given without domain!" % string)
97
98 locales = translator._localedirs
99
100 pot_data = {}
101
102 for domain, strings in strings_by_domain.iteritems():
103 if domain not in locales.keys():
104 self.fail("Missing domain '%s'" % domain)
105
106 for string in strings:
107 value = False
108 for localedir in locales[domain]:
109
110 if localedir not in pot_data.keys():
111
112 messages = os.path.join(localedir, 'messages.pot')
113 if not os.path.isfile(messages):
114
115 continue
116 mes_read = open(messages, 'r')
117 pot_data[localedir] = mes_read.read()
118 mes_read.close()
119
120 data = pot_data[localedir]
121
122 if '\nmsgid "%s"\n' % string in data:
123 value = True
124 break
125
126 if not value:
127 self.fail("'%s' not found in the translation template for" \
128 " '%s': '%r'" % (string, domain, locales[domain]))
129