How do I translate site.name to other languages?

40 vistas
Ir al primer mensaje no leído

Uri Even-Chen

no leída,
22 dic 2016, 12:41:47 p.m.22/12/2016
para django...@googlegroups.com
Hi Django users,

We have our site.name and other site names (we have 4 sites in Django right now) in templates such as base.html. The site is taken from model Site (```from django.contrib.sites.models import Site```). In templates we just use "{{ site.name }}" or "{{ other_site.name }}". How do we translate these site names to other languages? What is the correct way? Currently I only need the site names in English and Hebrew, but maybe later I will want other languages too.

Our settings file translates the site title. Is it better to translate it in the templates? Because we don't want to translate it twice. If the site title is not defined, the default is the site name (which we want for 2 of our sites). But we need it translated.

from django.conf import settings as dj_settings
from django.contrib.sites.models import Site


def sites(request):
site = Site.objects.get_current()
site_title = site.name
if hasattr(dj_settings, 'SITE_TITLE'):
site_title = dj_settings.SITE_TITLE
return {
'site': site,
'site_title': site_title,
'sites': Site.objects.all().order_by('pk'),
}

You can see the code on GitHub: https://github.com/urievenchen/speedy-net

Thanks,
Uri.

Uri Even-Chen  
photo Phone: +972-54-3995700
Email: u...@speedy.net
Website: http://www.speedysoftware.com/uri/en/
    

Melvyn Sopacua

no leída,
25 dic 2016, 6:00:53 p.m.25/12/2016
para django...@googlegroups.com

Hi Uri,

 

On Thursday 22 December 2016 19:40:15 Uri Even-Chen wrote:

 

> We have our site.name and other site names (we have 4 sites in Django

> right now) in templates such as base.html. The site is taken from

> model Site (```from django.contrib.sites.models import Site```).

 

Untested, but since Site is a Django Model, have a look at Django Model Translation. I suspect once you get the idea, you'll use it throughout the project.

--

Melvyn Sopacua

Uri Even-Chen

no leída,
26 dic 2016, 6:32:41 a.m.26/12/2016
para django...@googlegroups.com
Thank you!



Uri Even-Chen  
photo Phone: +972-54-3995700
Email: u...@speedy.net
Website: http://www.speedysoftware.com/uri/en/
    

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1672133.RzSWr4WvZz%40devstation.
For more options, visit https://groups.google.com/d/optout.

Uri Even-Chen

no leída,
29 dic 2016, 6:52:41 a.m.29/12/2016
para django...@googlegroups.com
Hi,

with django-modeltranslation you can add translations to any model, even if it's built-in in Django, but the problem is that migrations are being created in site-packages, outside our git repo, and this would cause issues upgrading Django itself.

(speedy_net)net$ ./manage.py makemigrations
Migrations for 'sites':
  /Users/xtr/.virtualenvs/speedy_net/lib/python3.5/site-packages/django/contrib/sites/migrations/0003_auto_20161229_1018.py:
    - Change managers on site
    - Add field name_en to site
    - Add field name_he to site

Is there a way to move the migrations to inside our git repo?

Thanks,
Uri.


Uri Even-Chen  
photo Phone: +972-54-3995700
Email: u...@speedy.net
Website: http://www.speedysoftware.com/uri/en/
    
On Mon, Dec 26, 2016 at 1:00 AM, Melvyn Sopacua <m.r.s...@gmail.com> wrote:

--
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos