def i18n_filter(stream, template, locale=None): """Kid template filter which calls translates all elements matching language attribute(set in configuration as i18n.templateLocaleAttribute, default 'lang') """ lang_attr = config.get("i18n.templateLocaleAttribute", "lang") locales = [locale] for ev, item in stream: if ev == START: l = item.get(lang_attr) if l: locale = l locales.append(l) elif ev == TEXT: prefix = "" postfix = "" if len(item) > 0 and item[0] == " ": prefix = " " if len(item) > 1 and item[-1] == " ": postfix = " " text = item.strip() if text: item = gettext(text, locale) item = prefix + item + postfix elif ev == END: if item.get(lang_attr): locales.pop() locale = locales[-1] yield (ev, item)
def i18n_filter(stream, template, locale=None): """Kid template filter which calls translates all elements matching language attribute(set in configuration as i18n.templateLocaleAttribute, default 'lang') """ lang_attr = config.get("i18n.templateLocaleAttribute", "lang") locales=[locale] for ev, item in stream: if ev==START: l = item.get(lang_attr) if l: locale = l locales.append(l) elif ev==TEXT: prefix = '' postfix = '' if len(item) > 0 and item[0] == ' ': prefix =' ' if len(item) > 1 and item[-1] == ' ': postfix =' ' text = item.strip() if text: item = gettext(text, locale) item = prefix + item + postfix elif ev==END: if item.get(lang_attr): locales.pop() locale = locales[-1] yield (ev, item)
def __translate_text(text, lang): prefix = "" postfix = "" if len(text) > 0 and text[0].isspace(): prefix = text[0] if len(text) > 1 and text[-1].isspace(): postfix = text[-1] return prefix + gettext(text.strip(), lang) + postfix
def __translate_text(text, lang): prefix = '' postfix = '' if len(text) > 0 and text[0].isspace(): prefix = text[0] if len(text) > 1 and text[-1].isspace(): postfix = text[-1] return prefix + gettext(text.strip(), lang) + postfix