diff --git a/README.md b/README.md index 3db6dd92..2564d7af 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,9 @@ Code contributions are gladly welcomed! If you're not sure where to start, take If you have questions about the project or contributing, you can set up a video call during BookWyrm ["office hours"](https://calendly.com/mouse-reeve/30min). +### Translation +Do you speak a language besides English? BookWyrm needs localization! If you're comfortable using git and want to get into the code, there are [instructions](#workin-with-translations-and-locale-files) on how to create and edit localization files. If you feel more comfortable working in a regular text editor and would prefer not to run the application, get in touch directly and we can figure out a system, like emailing a text file, that works best. + ### Financial Support BookWyrm is an ad-free passion project with no intentions of seeking out venture funding or corporate financial relationships. If you want to help keep the project going, you can donate to the [Patreon](https://www.patreon.com/bookwyrm), or make a one time gift via [PayPal](https://paypal.me/oulipo). @@ -68,7 +71,7 @@ Since the project is still in its early stages, the features are growing every d - Private, followers-only, and public privacy levels for posting, shelves, and lists - Option for users to manually approve followers - Allow blocking and flagging for moderation - + ### The Tech Stack Web backend - [Django](https://www.djangoproject.com/) web server @@ -76,12 +79,12 @@ Web backend - [ActivityPub](http://activitypub.rocks/) federation - [Celery](http://celeryproject.org/) task queuing - [Redis](https://redis.io/) task backend - + Front end - Django templates - [Bulma.io](https://bulma.io/) css framework - Vanilla JavaScript, in moderation - + Deployment - [Docker](https://www.docker.com/) and docker-compose - [Gunicorn](https://gunicorn.org/) web runner @@ -109,6 +112,33 @@ docker-compose up Once the build is complete, you can access the instance at `localhost:1333` +### Editing static files +If you edit the CSS or JavaScript, you will need to run Django's `collectstatic` command in order for your changes to have effect. You can do this by running: +``` bash +./bw-dev collectstatic +``` + +### Workin with translations and locale files +Text in the html files are wrapped in translation tags (`{% trans %}` and `{% blocktrans %}`), and Django generates locale files for all the strings in which you can add translations for the text. You can find existing translations in the `locale/` directory. + +The application's language is set by a request header sent by your browser to the application, so to change the language of the application, you can change the default language requested by your browser. + +#### Adding a locale +To start translation into a language which is currently supported, run the django-admin `makemessages` command with the language code for the language you want to add (like `de` for German, or `en-gb` for British English): +``` bash +./bw-dev makemessages -l +``` + +#### Editing a locale +When you have a locale file, open the `django.po` in the directory for the language (for example, if you were adding German, `locale/de/LC_MESSAGES/django.po`. All the the text in the application will be shown in paired strings, with `msgid` as the original text, and `msgstr` as the translation (by default, this is set to an empty string, and will display the original text). + +Add you translations to the `msgstr` strings, and when you're ready, compile the locale by running: +``` bash +./bw-dev compilemessages +``` + +You can add the `-l ` to only compile one language. When you refresh the application, you should see your translations at work. + ## Installing in Production This project is still young and isn't, at the moment, very stable, so please proceed with caution when running in production. diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 46c38b5a..9446b09c 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -1,9 +1,10 @@ ''' bookwyrm settings and configuration ''' import os - from environs import Env import requests +from django.utils.translation import gettext_lazy as _ + env = Env() DOMAIN = env('DOMAIN') @@ -27,6 +28,7 @@ EMAIL_USE_TLS = env('EMAIL_USE_TLS', True) # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale'),] # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ @@ -58,6 +60,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -135,6 +138,10 @@ AUTH_PASSWORD_VALIDATORS = [ # https://docs.djangoproject.com/en/2.0/topics/i18n/ LANGUAGE_CODE = 'en-us' +LANGUAGES = [ + ('en-us', _('English')), +] + TIME_ZONE = 'UTC' diff --git a/bookwyrm/templates/author.html b/bookwyrm/templates/author.html index 9f2054d0..9dd83189 100644 --- a/bookwyrm/templates/author.html +++ b/bookwyrm/templates/author.html @@ -1,4 +1,5 @@ {% extends 'layout.html' %} +{% load i18n %} {% load bookwyrm_tags %} {% block content %}
@@ -9,8 +10,8 @@ {% if request.user.is_authenticated and perms.bookwyrm.edit_book %} @@ -25,12 +26,12 @@

{% endif %} {% if author.wikipedia_link %} -

Wikipedia

+

{% trans "Wikipedia" %}

{% endif %}
-

Books by {{ author.name }}

+

{% blocktrans with name=author.name %}Books by {{ name }}{% endblocktrans %}

{% include 'snippets/book_tiles.html' with books=books %}
{% endblock %} diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book.html index dc7d4ce8..35ddba37 100644 --- a/bookwyrm/templates/book.html +++ b/bookwyrm/templates/book.html @@ -1,4 +1,5 @@ {% extends 'layout.html' %} +{% load i18n %} {% load bookwyrm_tags %} {% load humanize %} {% block content %} @@ -23,8 +24,8 @@ {% if request.user.is_authenticated and perms.bookwyrm.edit_book %} @@ -39,13 +40,13 @@ {% if request.user.is_authenticated and not book.cover %}
-

Add cover

+

{% trans "Add cover" %}

{% csrf_token %} - +
{% endif %} @@ -54,21 +55,21 @@
{% if book.isbn_13 %}
-
ISBN:
+
{% trans "ISBN:" %}
{{ book.isbn_13 }}
{% endif %} {% if book.oclc_number %}
-
OCLC Number:
+
{% trans "OCLC Number:" %}
{{ book.oclc_number }}
{% endif %} {% if book.asin %}
-
ASIN:
+
{% trans "ASIN:" %}
{{ book.asin }}
{% endif %} @@ -80,7 +81,7 @@

{% if book.openlibrary_key %} -

View on OpenLibrary

+

{% trans "View on OpenLibrary" %}

{% endif %} @@ -98,11 +99,11 @@
{% csrf_token %}

- +

- + {% include 'snippets/toggle/close_button.html' with text="Cancel" controls_text="add-description" controls_uid=book.id hide_inactive=True %}
@@ -134,20 +135,20 @@ {% if request.user.is_authenticated %}
-

Your reading activity

+

{% trans "Your reading activity" %}

{% include 'snippets/toggle/open_button.html' with text="Add read dates" icon="plus" class="is-small" controls_text="add-readthrough" %}
{% if not readthroughs.exists %} -

You don't have any reading activity for this book.

+

{% trans "You don't have any reading activity for this book." %}

{% endif %}