Skip to content

Commit

Permalink
css: Add dark theme
Browse files Browse the repository at this point in the history
- add CSS override for dark theme
- add javascript to toggle that
- allow to override this in the profile

Fixes WeblateOrg#2969
  • Loading branch information
nijel committed Jun 8, 2023
1 parent 968db45 commit 567ae70
Show file tree
Hide file tree
Showing 8 changed files with 2,719 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Not yet released.
* Project stats exports to JSON/CSV now include more details; it now matches content available in the API.
* Added check for reused translation.
* Highlight suggested change in automatic suggestions.
* Added dark theme, it follows browser settings, but can be chosen manually.

`All changes in detail <https://github.com/WeblateOrg/weblate/milestone/97?closed=1>`__.

Expand Down
5 changes: 5 additions & 0 deletions docs/user/profile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ the Hebrew language is shown as secondarily:
Preferences
-----------

Theme
+++++

Choose whether Weblate will follow system settings for dark or light theme or choose one of them.

Default dashboard view
++++++++++++++++++++++

Expand Down
1 change: 1 addition & 0 deletions weblate/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class UserSettingsForm(ProfileBaseForm):
class Meta:
model = Profile
fields = (
"theme",
"hide_completed",
"translate_mode",
"zen_mode",
Expand Down
30 changes: 30 additions & 0 deletions weblate/accounts/migrations/0025_profile_theme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

# Generated by Django 4.2.1 on 2023-06-08 12:24

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("accounts", "0024_rename_be_latn"),
]

operations = [
migrations.AddField(
model_name="profile",
name="theme",
field=models.CharField(
choices=[
("auto", "Sync with system"),
("light", "Light"),
("dark", "Dark"),
],
default="auto",
max_length=10,
verbose_name="Theme",
),
),
]
14 changes: 12 additions & 2 deletions weblate/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.dispatch import receiver
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.translation import get_language, gettext, gettext_lazy
from django.utils.translation import get_language, gettext, gettext_lazy, pgettext_lazy
from rest_framework.authtoken.models import Token
from social_django.models import UserSocialAuth

Expand Down Expand Up @@ -395,7 +395,16 @@ class Profile(models.Model):
translated = models.IntegerField(default=0, db_index=True)
uploaded = models.IntegerField(default=0, db_index=True)
commented = models.IntegerField(default=0, db_index=True)

theme = models.CharField(
max_length=10,
verbose_name=gettext_lazy("Theme"),
default="auto",
choices=(
("auto", pgettext_lazy("Theme selection", "Sync with system")),
("light", pgettext_lazy("Theme selection", "Light")),
("dark", pgettext_lazy("Theme selection", "Dark")),
),
)
hide_completed = models.BooleanField(
verbose_name=gettext_lazy("Hide completed translations on the dashboard"),
default=False,
Expand Down Expand Up @@ -663,6 +672,7 @@ def dump_object(obj, *attrs):
"translated",
"uploaded",
"hide_completed",
"theme",
"secondary_in_zen",
"hide_source_secondary",
"editor_link",
Expand Down
4 changes: 4 additions & 0 deletions weblate/static/style-bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

:root {
color-scheme: only light;
}

.avatar {
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
Expand Down

0 comments on commit 567ae70

Please sign in to comment.