Re: django ugettext translation glitch or as designed?

2014-05-30 Thread visionary800
Thank you Ramiro!  That was it - I changed to ugettext_lazy() and it worked!

I want to separate the text from the templates - this is why I want to 
place the text in a separate file.  Placing the text within the template is 
a d

What approach should I take to just separate the text from from the 
templates and views?  I want the text easy to edit without worrying about 
tags around the text.  Any suggestions? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2bad743d-d190-4ed1-affb-932e5c1e9236%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django ugettext translation glitch or as designed?

2014-05-30 Thread Ramiro Morales
On Fri, May 30, 2014 at 10:51 PM, visionary800  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.

In example 2 your translatable literal is defined and marked-up with
the translation function at the global scope of the module. In these
cases you need to use lazy translations, i.e. ugettext_lazy() instead
of ugettext().

Read the the relevant documentation carefully for the details:

https://docs.djangoproject.com/en/1.6/topics/i18n/translation/#lazy-translation

HTH,

-- 
Ramiro Morales
@ramiromorales

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO7PdF9uu7BF%2Bf5DK5kXa%2B5NeSQmne89N2x%3DGEwxLckQYyTBig%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django ugettext translation glitch or as designed?

2014-05-30 Thread visionary800
Sorry for the large text... I forget to change it - I guess I am going 
blind :-)

On Friday, May 30, 2014 6:51:35 PM UTC-7, visionary800 wrote:
>
> I am running into a challenge.  For both examples below everything is good 
> except when I move the ugettext() to a separate file.
> Good: After running the django-admin.py makemessages -l es, both examples 
> produce the appropriate .po file.
> Good: I change ../locale/es/LC_MESSAGES/django.po
>   #: nav/views.py: 
>   msgid "name" 
>  msgstr "nombre"
> Good: django-admin.py compilemessages
> Good: I get the appropriate file, ../locale/es/LC_MESSAGES/django.mo 
>
> This is a simplified version of what is happening.
>
>
> ---
> Good: 1 - This works: when ugettext is within the view.
> *file : /project/app/views.py*
>
> ...other imports
> from django.utils.translation import ugettext
>
> 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']= ugettext('name')
>return context
>
> -
>
> 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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ad352064-6e11-4f0c-89a6-a0fab2d091c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django ugettext translation glitch or as designed?

2014-05-30 Thread visionary800
I am running into a challenge.  For both examples below everything is good 
except when I move the ugettext() to a separate file.
Good: After running the django-admin.py makemessages -l es, both examples 
produce the appropriate .po file.
Good: I change ../locale/es/LC_MESSAGES/django.po
  #: nav/views.py: 
  msgid "name" 
 msgstr "nombre"
Good: django-admin.py compilemessages
Good: I get the appropriate file, ../locale/es/LC_MESSAGES/django.mo 

This is a simplified version of what is happening.

---
Good: 1 - This works: when ugettext is within the view.
*file : /project/app/views.py*

...other imports
from django.utils.translation import ugettext

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']= ugettext('name')
   return context
-

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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2302f88c-2050-4265-bf22-6e4d34a2b486%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.