On Fri, May 30, 2014 at 10:51 PM, visionary800 <
drjose...@gmail.com> wrote:
> Bad: 2 - This Fails: when ugettext is in another file
> file : /project/app/views.py
>
> ...other imports
> from .mytext import FROM_ANOTHER_FILE
>
> class BaseView(ContextMixin, View):
> template = 'base.html'
>
> def get(self, request, *args, **kwargs):
> context = self.get_context_data()
> return render(request, self.template, context)
>
> def get_context_data(self, **kwargs):
> ....
> context['translate_this']= FROM_ANOTHER_FILE
> return context
>
> file: /project/app/text.py
> from django.utils.translation import ugettext
>
> FROM_ANOTHER_FILE = ugettext('name')
>
> -------------------------------------------------------------------------
>
> The primary difference between the two examples is that when I separate
> ugettext() to another file - it fails.
> The result is that 'name' never converts to 'nombre' when changing the
> language.
> It works fine in example 1, 'name' and 'nombre' change depending on language
> selected but not in example 2.
the translation function at the global scope of the module. In these
cases you need to use lazy translations, i.e. ugettext_lazy() instead