32 |
except: |
except: |
33 |
def XML(v): |
def XML(v): |
34 |
return str(v) |
return str(v) |
|
try: |
|
|
True |
|
|
except NameError: |
|
|
True=1 |
|
|
False=0 |
|
35 |
|
|
36 |
def log(msg, severity=zLOG.INFO, detail='', error=None): |
def log(msg, severity=zLOG.INFO, detail='', error=None): |
37 |
if type(msg) is UnicodeType: |
if type(msg) is UnicodeType: |
125 |
self._delObject(catalog.id) |
self._delObject(catalog.id) |
126 |
except: |
except: |
127 |
pass |
pass |
128 |
self._setObject(catalog.id, catalog, set_owner=False) |
self._setObject(catalog.id, catalog, set_owner=0) |
129 |
log('adding %s: %s' % (catalog.id, catalog.title)) |
log('adding %s: %s' % (catalog.id, catalog.title)) |
130 |
self._registerMessageCatalog(catalog) |
self._registerMessageCatalog(catalog) |
131 |
|
|
178 |
pass |
pass |
179 |
|
|
180 |
if target_language is None: |
if target_language is None: |
181 |
if context is None: |
target_language = self.negotiate_language(context, domain) |
|
raise TypeError, 'No destination language' |
|
|
else: |
|
|
langs = [m[0] for m in self._catalogs.keys() if m[1] == domain] |
|
|
for fallback in self._fallbacks: |
|
|
if fallback not in langs: |
|
|
langs.append(fallback) |
|
|
target_language = self.negotiate(langs, context) |
|
182 |
|
|
183 |
# Get the translation. Use the specified fallbacks if this fails |
# Get the translation. Use the specified fallbacks if this fails |
184 |
catalog_names = self._catalogs.get((target_language, domain), ()) |
catalog_names = self._catalogs.get((target_language, domain), ()) |
216 |
text = self.interpolate(text, mapping) |
text = self.interpolate(text, mapping) |
217 |
return text |
return text |
218 |
|
|
219 |
|
def negotiate_language(self, context, domain): |
220 |
|
if context is None: |
221 |
|
raise TypeError, 'No destination language' |
222 |
|
else: |
223 |
|
langs = [m[0] for m in self._catalogs.keys() if m[1] == domain] |
224 |
|
for fallback in self._fallbacks: |
225 |
|
if fallback not in langs: |
226 |
|
langs.append(fallback) |
227 |
|
target_language = self.negotiate(langs, context) |
228 |
|
return target_language |
229 |
|
|
230 |
def getDomain(self, domain): |
def getDomain(self, domain): |
231 |
""" |
""" |
232 |
""" |
""" |
251 |
# Find all the spots we want to substitute |
# Find all the spots we want to substitute |
252 |
to_replace = _interp_regex.findall(text) |
to_replace = _interp_regex.findall(text) |
253 |
|
|
254 |
|
# ZPT (string) or OpenPT (unicode)? |
255 |
|
if type(text) is StringType: |
256 |
|
conv = str |
257 |
|
else: |
258 |
|
conv = XML |
259 |
|
|
260 |
# Now substitute with the variables in mapping |
# Now substitute with the variables in mapping |
261 |
for string in to_replace: |
for string in to_replace: |
262 |
var = _get_var_regex.findall(string)[0] |
var = _get_var_regex.findall(string)[0] |
271 |
# FIXME: we shouldn't do this. We should instead |
# FIXME: we shouldn't do this. We should instead |
272 |
# return a list. But i'm not sure about how to use |
# return a list. But i'm not sure about how to use |
273 |
# the regex to split the text. |
# the regex to split the text. |
274 |
value = XML(value) |
value = conv(value) |
275 |
text = text.replace(string, value) |
text = text.replace(string, value) |
276 |
|
|
277 |
return text |
return text |