I want to change the language of timesince. Do I need to change directly in my django source or is there a way to modify TIMESINCE_CHUNKS variable in the settings file?
You have to ./manage.py makemessages.
Then edit the .po files and then ./manage.py compilemessages.
For this to work, however, you have to go through the internationalization chapter, and of course its implementation notes.
Related
In my webapp, I'd like to allow users who want to deploy an instance to write their own templates. Specifically, I would like to include a template for a data protection declaration using the include tag and have this point to a location which users can define in their settings.
However, this would not be translatable, as all translated strings have to be in django.po and that file is in version control.
Is there a way to extend django.po, e.g. use an include statement to point it to a second, user generated translations file, similar to how I can include templates within other templates?
Not entirely sure if this is possible, but you best bet is probably to use some other mechanism for translation. For example, you could create a template-tag user_translation and make it fetch the translation from the database or settings.
I am using:
Python 2.7
Django 1.6.11
Mezzanine 3.1.10
Anyone who logins in my blog website can set the "name" field of the comments form for a blog post. I had the idea to hide this field but I can't find the template for the comment form.
Does anyone know where the comment form template is or another way to prevent users from setting the "name" field for comments?
You can try to change the templates by first copying the relevant template into your static/templates directory. Use the command
./manage.py findstatic templates\something.html
Ensure that your static files directory is set, then check that
./manage.py findstatic templates\something.html
finds both files, one from mezzanine and one from your static directory.
Example:
./manage.py findstatic css\bootstrap.css
Found 'css\bootstrap.css' here:
C:\Python34\lib\site-packages\mezzanine\core\static\css\bootstrap.css
c:\users\me\documents\mezz-project\mez\static\css\bootstrap.css
I'm trying to override the default translations of Django's admin site.
I'm using Django 1.6. My settings.py contains:
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# ...
LANGUAGE_CODE = 'nl'
USE_I18N = True
USE_L10N = True
LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),)
I have copied the file django/contrib/admin/locale/nl/LC_MESSAGES/django.po to my_project/locale/nl/LC_MESSAGES/django.po and I've made some changes to it.
Next, I have run python manage.py compilemessages and python manage.py runserver.
When I visit localhost:8000/admin, however, I'm still seeing Django's default admin translations. What am I doing wrong?
Edit - I found the problem:
The above description is the correct way to override app translations. I followed my own instructions and they work. The reason for my problem was that I accidentally omitted the nl subdirectory the first time. I am a dumb person.
I'm providing an answer, even though #hedgie mostly answered their own question. I'll add a bit of context and description of what's happening. This answer is still applicable as of Django 3.0.
Just as you can override a Django-provided admin template by duplicating the template's name and directory structure within our own project, you can override Django-provided admin translations by duplicating a .po file's name and directory structure within our project.
Django's admin translations live in django/contrib/admin/locale/ and are organized by language in directories named [language code]/LC_MESSAGES/. These individual language directories contain two .po files, django.po and djangojs.po, and their respective compiled .mo files. You will be overriding the .po files, and compiling our own .mo files.
The first thing you have to do is enable translations in settings, and tell Django where you store our translation files.
settings.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# ...
LANGUAGE_CODE = 'nl-NL'
USE_I18N = True
USE_L10N = True
LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),) # our custom translations will go here
Note that although the directory Django uses is nl, the full language identifier for Dutch in the Netherlands is nl-NL. You can find a full list of identifiers organized by country here.
Next, you'll mimic Django's directory structure and create two files in a new directory:
my_project/locale/nl/LC_MESSAGES/django.po
my_project/locale/nl/LC_MESSAGES/djangojs.po
Note that this path must also match what you provided in settings.py.
Copy and paste the contents of Django's translation files. You can now edit the translations for whichever strings you like. For example:
django.po
msgid "Are you sure?"
--- msgstr "Weet u het zeker?"
+++ msgstr "Weet u het zeker?!"
Now you need to compile the messages with:
python manage.py compilemessages
This command compiles your .po files into .mo files, which Django will use to translate any matching gettext calls. You should now see your custom translations in the admin interface.
I'm using Django and I'm wondering whether it's proper to use myapp.models, opposed to myproject.myapp.models, or in INSTALLED_APPS, should the FULL NAME be used myproject.myapp or is it alright to just use myapp for it's name? I am wondering because if I were to change the project name using the latter method it would break my app, but I'm not sure that just because the former method works that it is correct. Could someone clear this up for me.
Thank you!
I would say that it is not encouraged to reference your apps using your project name. I say this because as of Django 1.4 this will not work with a default Django project. You can read more about this here:
https://docs.djangoproject.com/en/dev/releases/1.4/#updated-default-project-layout-and-manage-py
A quote from that:
"If settings, URLconfs and apps within the project are imported or referenced using the project name prefix (e.g. myproject.settings, ROOT_URLCONF = "myproject.urls", etc), the new manage.py will need to be moved one directory up, so it is outside the project package rather than adjacent to settings.py and urls.py."
I would recommend against it since it would mean messing with the default project structure, not a huge deal, but increased unnecessary work.
I would also recommend against it since it couples your apps to your project, which imho goes against the philosophy of Django which advocates reusable, decoupled apps.
In my Django app i have the usual django.po locale file under each of the languages. However, I'd like to create a custom locale file called custom.po. Is there any way I could Django to first check for a translation string in the custom.po file and if it doesn't exist, check the django.po file
Thanks.
Check the LOCALE_PATHS setting. This tuple is order-specific, so if you put the path to your custom.po first, you will achieve the effect you're after.
Edit: Additional link for detailed information about How Django discovers translations.