diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 5acde9ea..c112186a 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -144,6 +144,7 @@ class EditUserForm(CustomForm): "default_post_privacy", "discoverable", "preferred_timezone", + "preferred_language", ] help_texts = {f: None for f in fields} diff --git a/bookwyrm/migrations/0106_user_preferred_language.py b/bookwyrm/migrations/0106_user_preferred_language.py new file mode 100644 index 00000000..a77030a0 --- /dev/null +++ b/bookwyrm/migrations/0106_user_preferred_language.py @@ -0,0 +1,30 @@ +# Generated by Django 3.2.5 on 2021-10-06 19:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0105_alter_connector_connector_file"), + ] + + operations = [ + migrations.AddField( + model_name="user", + name="preferred_language", + field=models.CharField( + blank=True, + choices=[ + ("en-us", "English"), + ("de-de", "German"), + ("es", "Spanish"), + ("fr-fr", "French"), + ("zh-hans", "Simplified Chinese"), + ("zh-hant", "Traditional Chinese"), + ], + max_length=255, + null=True, + ), + ), + ] diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 637baa6e..d7945843 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -17,7 +17,7 @@ from bookwyrm.connectors import get_data, ConnectorException from bookwyrm.models.shelf import Shelf from bookwyrm.models.status import Status, Review from bookwyrm.preview_images import generate_user_preview_image_task -from bookwyrm.settings import DOMAIN, ENABLE_PREVIEW_IMAGES, USE_HTTPS +from bookwyrm.settings import DOMAIN, ENABLE_PREVIEW_IMAGES, USE_HTTPS, LANGUAGES from bookwyrm.signatures import create_key_pair from bookwyrm.tasks import app from bookwyrm.utils import regex @@ -133,6 +133,12 @@ class User(OrderedCollectionPageMixin, AbstractUser): default=str(pytz.utc), max_length=255, ) + preferred_language = models.CharField( + choices=LANGUAGES, + null=True, + blank=True, + max_length=255, + ) deactivation_reason = models.CharField( max_length=255, choices=DeactivationReason, null=True, blank=True ) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index b2f90487..00ce9e4a 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -30,6 +30,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) LOCALE_PATHS = [ os.path.join(BASE_DIR, "locale"), ] +LANGUAGE_COOKIE_NAME = env.str("LANGUAGE_COOKIE_NAME", "django_language") DEFAULT_AUTO_FIELD = "django.db.models.AutoField" diff --git a/bookwyrm/templates/preferences/edit_user.html b/bookwyrm/templates/preferences/edit_user.html index f3cabbc7..72c49dbe 100644 --- a/bookwyrm/templates/preferences/edit_user.html +++ b/bookwyrm/templates/preferences/edit_user.html @@ -91,6 +91,12 @@ {{ form.preferred_timezone }} +