def render(self, context): # Try to get request.LANGUAGE_CODE. If fail, use default one. request = context['request'] language = get_language_from_request(request, default=None) if not language: language = smart_resolve(self.language, context) if not language in get_languages_keys(): language = default_language translation.activate(language) return ''
def render(self, context): ret_val = None obj = smart_resolve(self.obj, context) try: is_multilingual = obj.is_multilingual except AttributeError as e: is_multilingual = False raise template.TemplateSyntaxError( _("Invalid usage of ``get_translated_object_for``. Translated object shall be multilingual.") ) try: request = context['request'] except: request = None if language is None and request is None: raise template.TemplateSyntaxError( _("Invalid usage of ``get_translated_object_for``. Can't retrieve ``HttpRequest`` object from " "template context, while ``language`` attribute is not specified.") ) if language is None: language = get_language_from_request(request) else: language = smart_resolve(self.language, context) if language: language = str(language) else: language = default_language ret_val = obj.get_translation_for(language) if self.as_var: context[self.as_var] = ret_val return '' return ret_val
def render(self, context): ret_val = None obj = smart_resolve(self.obj, context) try: is_multilingual = obj.is_multilingual except AttributeError as e: is_multilingual = False raise template.TemplateSyntaxError( _("Invalid usage of get_translated_object_for. Translated object shall be multilingual.") ) ret_val = obj.available_translations() if self.as_var: context[self.as_var] = ret_val return '' return ret_val