Ejemplo n.º 1
0
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 = turbogears.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)
Ejemplo n.º 2
0
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 = turbogears.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)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def i18n_filter(stream, template, locale=None):
    """Kid template filter translating all elements matching lang attribute.

    The name of of the attribute is set in the configuration as
    'i18n.templateLocaleAttribute' and defaults to '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)
Ejemplo n.º 5
0
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