Developer Howtos
Viewing logs
To view the logs when running the app locally, run:
docker-compose logs -f
Creating Migration Files
With docker:
make manage makemigrations
Without Docker
python manage.py makemigrations
Running Migrations
With docker:
make manage migrate
Without Docker
python manage.py migrate
Emails in local env
When you sign up you'll receive an email with a code to verify your account. In Development those emails don't leave your machine so here's the steps to get the code.
With Docker
The docker compose development environment includes a maildev instance for previewing emails locally.
It is accessible at http://localhost:1080 and will show all emails sent by the application.
Without Docker
Check your terminal, the email will be printed out for you.
Set up your Account as a Staff user
- Go to http://localhost:8000/accounts/login/
- Go to the "Sign up" link
- Fill in the email address, username, and password.
- Upon signing up, the confirmation email will be available either at http://localhost:1080/ (if you are running with Docker) or printed on the terminal (if you are running without Docker). Enter this code on the sign up form.
- Your account is now verified.
- On the terminal, go to Django shell:
With Docker:
make manage shell
Without Docker
python manage.py shell
- Set your account as a staff and superuser:
from django.contrib.auth.models import User
user = User.objects.get(username='your_username') # use the username you created above
user.is_staff = True
user.is_superuser = True
user.save()
Then exit the console and re-run the server.
- You can now access the
/admin
page at http://localhost:8000/admin.
Add transalations and new languages
To create translations/localization we use the Django itself.
Note: for now you can only run localization without Docker.
Translating content
Translation files live inside the locale/
folder.
For each language there's a subfolder for example pt_BR
for Portuguese from Brazil.
In each language folder there are two files:
.mo
: file with the compiled translation.po
: file containing the strings to be translated - this is the file you'll edit to translate the words.
To update the translation for your preferred language:
- Follow the development setup guide without Docker.
- Then open the
.po
file for the language you want to translate and find the phrase you want to translate.
For example, in the file locale/pt_BR/LC_MESSAGES/django.po
there's the following phrase:
#: templates/portal/index.html:21
msgid ""
"Sign up to volunteer with us! Fill in your Volunteer profile and we'll get "
"you set up."
msgstr ""
To show it in Portuguese you add the translation into the msgstr
like this:
#: templates/portal/index.html:21
msgid ""
"Sign up to volunteer with us! Fill in your Volunteer profile and we'll get "
"you set up."
msgstr "Inscreva-se para ser voluntária conosco! Preencha seu perfil de Voluntária e nós vamos te cadastrar."
Creating new languages translation files
To create new translations files for different languages you must:
- Update the
LANGUAGE
variable inportal/settings.py
# ...
LANGUAGES = (
("pt-br", "Português"),
("en-us", "English"),
)
- Then you should run the
makemessages
command:
python manage.py makemessages -l <locale-code>
For example for Brazilian Portuguese:
python manage.py makemessages -l pt_BR
Note that for the makemessages command we uses ISO/IEC 15897 for formatting of the language tag.
-
Translate a couple of messages in the generated
.po
file; -
Then complile the translations with:
python manage.py compilemessages
Run your server if it isn't running yet and you'll should see the new language in the language selector.
Missing translation strings
What if you don't see a phrase in to translate in the .po file?
You probaly need to find that phrase in the HTML files inside the templates
folder and add a tag translate
into it like so:
<p>
{% translate "Sign up %}
</p>
Then run the creation command again.