Django CMS and Rosetta: Can't get template messages translated - django

Is there any know issue about using Django CMS and Django Rosetta together.
I cant get the "static" template messages translated although it appears correctly translated in the Rosetta interface.
All the dynamic content is correctly translated. Only the one I´ve set up around the `{% trans 'blabla' %} does not work.

Gotcha!
Just add in settings.py
LOCALE_PATHS = (BASE_DIR + "/locale/",)
It worked for me.

Related

change verbose name of VISIT SITE in django 2.x admin

I only seem to find answers around changing the actual link of VISIT PAGE. How however can I change the verbose name to e.g. HOMEPAGE?
Below code only changes the actual link:
class AdminSite:
admin.site.site_url = "/hompeage"
What I'd like to achieve:
I'm looking to achieve this in the admin.py file of my application.
I haven't personally tried any ways, but looking the code
You can do it in two ways,
Override the base.html template on admin.
See: Django Github base.html
{% translate 'View site' %}
to
HomePage
If you look the code, it uses translation for
{% translate 'View site' %}
You can simply, override the locale string too.
See: Django Github en locale

How can I use Django's translation strings with Wagtailtrans (Add-on for supporting multi language Wagtail sites)

So I have a website which is using the Wagtailtrans extension for Wagtail. I basically enables multi language by duplicating the page tree. So the url gets fixed with the language-code at the start.
I can translate all my content which I define through my models perfectly fine. Here's an example of how that works:
class ServicesPage(MetadataPageMixin, TranslatablePage):
description = models.CharField(max_length=255, blank=True,)
content_panels = Page.content_panels + [
FieldPanel('description', classname="full")
]
Instead of Page you define it as TranslatablePage in your model. All is working fine, however I still need some additional strings which I don't define in my models to be translated. I just use Django's translation feature with {% load i18n %} and then the strings wrapped inside {% trans "String" %}.
So far so good, I defined my two languages in Wagtail admin (Wagtail trans creates an option for that) which in this case is English and Dutch. I set English as the main language so the strings are in english.
I use ./manage.py makemessages and it creates a .po file for me, with all the tagged strings in there. At last I use ./manage.py compilemessages.
But translated strings are not showing up when I switch to Dutch language, it still displays the english strings. So I suspect it needs some additional tweaking to work with Wagtailtrans, but I can't seem to figure out how this set-up should be. Can anyone help me out?

django url NoReverseMatch works in 3rd party app but not my project

I am integrating django-zinnia 0.12.3 into my django 1.4 project. I have it installed and working. I want to override its zinnia/base.html template so that all the content appears using my site's template. The zinnia templates extend 'zinnia/base.html'.
When I copy the file zinnia/templates/zinnia/base.html to myproject/templates/zinnia/base.html all the zinnia {% url %} stopped working and gave NoReverseMatch. Even if I made zero changes to the file. For example:
{% url 'zinnia_entry_archive_index' %} --> returns:
NoReverseMatch Reverse for ''zinnia_entry_archive_index'' ... not found
{% url 'admin:app_list' 'zinnia' %}" title="{% trans "Dashboard" %} --> returns:
NoReverseMatch u"'admin" is not a registered namespace
I was solved the problem by removing the quotes around the url names, for example:
{% url zinnia_entry_archive_index %}
However, if I remove the copy of base.html that I put in myproject/templates/zinnia (in other words it uses the original one in the zinnia project), the urls work again.
My question is why does it work with the quotes inside the original zinnia folder, but not from within my project folder?
The reason is that in Django <= 3 the url tag takes url name without quotes. But in Django 1.4+ it is deprecated and url name without quotes is gone in Django 1.5:
So if you are using Django <= 1.4 do not remove the quotes (unless you are passing context variable) around url names. Instead do this for compatibility reason if you ever wanted to upgrade your django version:
{% load url from future %}
{% url 'zinnia_entry_archive_index' %}
Documentation
Don’t forget to put quotes around the function path or pattern name!
Changed in Django 1.5: The first parameter used not to be quoted, which was inconsistent > with other template tags. Since Django 1.5, it is evaluated according to the usual rules: > it can be a quoted string or a variable that will be looked up in the context.

{% url %} gives me NoReverseMatch error while reverse() returns the url just fine. Why?

I don't know if this SO question is of the same problem that I am about to describe, but it does share the same symptoms. Unfortunately, it still remains unresolved as I am writing.
So here is my problem. I am trying to add James Bennett's django-registration app to my django project. I have pretty much finished configuring it to my needs - custom templates and urls. Just when I thought everything was good to go. I got NoReverseMatch error from using {% url 'testing' item_id=123 %} (I also tried using the view name, myapp.views.test, instead but no luck) in one of the custom templates required by django-registration. Interestingly, I tried reverse('testing', kwargs={'item_id':123}) in the shell and the url was returned just fine. I thought {% url %} uses reverse() in the back-end but why did I get different outcomes?
urls.py: (the URLconf of my site)
urlpatterns = patterns('myapp.views',
url(r'^test/(?P<item_id>\d+)/$', 'test', name='testing'),
)
activation_email.txt: (the said template. Note it's intentionally in .txt extension as required by django-registration and that shouldn't be the cause of the problem.)
{% comment %}Used to generate the body of the activation email.{% endcomment %}
Welcome to {{ site }}! Please activate your account by clicking on the following link:
{% url 'testing' item_id=123 %}
Note the activation link/code will be expired in {{ expiration_days }} days.
I don't know if it matters but just thought I should mention activation_email.txt is stored in the templates directory of myapp though it is used by django-registration.
Also, I am using django 1.4
I have a feeling that the problem has something to do with the url namespaces, a topic that I have never understood, but it's just a naive guess. (IMO, the django documentation is great in explaining everything about django, except when it comes to url namespaces)
I'm no expert here, but in a Django project I'm working on at the moment I use the name of the url without quotes. I just added quotes around a similar line in one of my templates and it produced the same error as your error.
Try:
{% url testing item_id=123 %}

GAE Django webapp2 template render

I have a question on template render in GAE. I would like to import a text file and write it to a html file. In this text file, I have used html symbols to tag new lines new paragraphs. It worked well with webapp. However, the same expression does not work with webapp2. So please give me some suggestions.
Thank you!
import webapp2
text_file2 = open('text1.txt','r')
x = text_file2.read()
html = html + template.render(templatepath + 'A.html', {'model_attributes':'Overview','text_paragraph':x})
I don't believe that the problem is webapp2 as much as it is Django 1.2, which is, I believe, the default version that you get with GAE as of a recent release of the SDK. The Django 1.2 templating engine differs from the 0.96 version in that it automatically HTML-escapes the content of template variables, and that is probably changing what you expect to see in your render page.
To fix it, you should add the |safe filter to the variable substitution in your template. So, if your template has something like this:
{{ text_paragraph }}
it should look like this:
{{ text_paragraph|safe }}
You can find out more information about this, including more options for dealing with Django's HTML-escaping here
And here is the official Django documentation on the safe filter.