Пример #1
0
def bidi(language):
    """ Return proper HTML attribute if the language is RTL """
    if language.rtl:
        return 'lang="%s" dir="rtl" style="text-align: right;"' % locale_to_language(language.code)
    else:
        return 'lang="%s" dir="ltr" style="text-align: left;"' % locale_to_language(language.code)
Пример #2
0
 def __init__(self, transunit, *args, **kwargs):
     """ Init the form """
     # Keep the translation
     translation = kwargs.pop('translation', transunit.translation)
     # Check if a translation text has been specified
     try:
         text = kwargs.pop('text')
     except KeyError:
         text = translation.text.replace('\t', r'\t').replace('\r', r'\r').replace('\n', r'\n' + '\n')
         comment = translation.comment
     else:
         comment = ''
     # Keep the translation propagation
     if args:
         self.propagation = args[0].pop('propagate-translation', ['p',])[0]
     else:
         self.propagation = 'p'
     # Find all alternate translations
     self.translations = transunit.translation.source.translation_set.select_related().filter(language = transunit.translation.language)
     # Init the parent
     super(TransunitForm, self).__init__(*args, **kwargs)
     # Current translation
     self.fields['translation'].initial = text
     self.fields['comment'].initial = comment
     # BiDi stuff
     if translation.language.rtl:
         self.fields['translation'].widget.attrs.update({'dir': 'rtl', 'style': 'text-align: right;', 'lang': locale_to_language(transunit.translation.language.code)})
     else:
         self.fields['translation'].widget.attrs.update({'dir': 'ltr', 'style': 'text-align: left;', 'lang': locale_to_language(transunit.translation.language.code)})
     # Keep the transunit
     self.transunit = transunit