Skip to content

Translate: support dark theme in editor#4176

Open
ayshushus wants to merge 8 commits into
mozilla:mainfrom
ayshushus:4001
Open

Translate: support dark theme in editor#4176
ayshushus wants to merge 8 commits into
mozilla:mainfrom
ayshushus:4001

Conversation

@ayshushus

@ayshushus ayshushus commented May 26, 2026

Copy link
Copy Markdown
Collaborator

Fix #4001

  • dark-theme.css / light-theme.css: rework --editor-{background,color,readonly-background,selection-background,placeholder-color}, --diff-*, --search-*, --tags-*, add --tags-string-color.
  • TranslationForm.css / editFieldExtensions.css: wire cm-cursor, cm-dropCursor, cm-selectionBackground, cm-placeholder, .translationform .accesskey-input to variables.
  • FailedChecks.css: warning icon color var(--grey-3) to var(--status-warning).

Per-user editor theme override (dark / light / match):

  • UserProfile.editor_theme CharField, default match; migration 0117_userprofile_editor_theme.
  • POST /user/editor-theme/ (toggle_editor_theme); user_editor_theme template helper for Jinja + Django; user_data view returns editor_theme.
  • Render data-editor-theme on <body> in base.html / allauth/layouts/base.html / translate.html.
  • theme_toggle.editor_button macro; split "Main" / "Editor" sections in contributors/settings.html; AJAX handler in theme-switcher.js.
  • ThemeContext exposes editorTheme; Editor.tsx applies ${editorTheme}-theme class on .editor to re-scope CSS variables to the editor subtree.

Tests in pontoon/contributors/tests/test_views.py for toggle_editor_theme (valid choices, invalid value, missing value, login required).

.github/workflows/backend.yml: install Node 24 (needed for npm-based pre-commit checks).

@ayshushus ayshushus self-assigned this May 26, 2026
@codecov-commenter

codecov-commenter commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.70968% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.64%. Comparing base (5a0c11f) to head (651bacf).
⚠️ Report is 12 commits behind head on main.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ayshushus ayshushus requested a review from functionzz June 1, 2026 20:39
@ayshushus ayshushus marked this pull request as ready for review June 1, 2026 20:39
@ayshushus

Copy link
Copy Markdown
Collaborator Author

Note that CodeMirror (autocomplete) is not inheriting here if we have an inverted color scheme.
image

@mathjazz

mathjazz commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Nice work!

Found minor issue in the theme selector - mind the missing border between the 2nd and the 3rd option when the 3rd option is selected:

Screenshot 2026-06-02 at 09 33 46

Some other observations:

  • If I select Main: dark & Editor: light I expect to get the current default theme. But the editor menu is light.
  • The editor background and the editor menu background should use the same color.

@mathjazz

mathjazz commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Some other observations:

If I select Main: dark & Editor: light I expect to get the current default theme. But the editor menu is light.

The editor background and the editor menu background should use [the same color.](https://github.com/mozilla/pontoon/pull/4129#issuecomment-4385769720)

Actually we decided to scratch that during the Pontoon call. Only the editor field is changing when changing the theme.

@mathjazz

mathjazz commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

.github/workflows/backend.yml: install Node 24 (needed for npm-based pre-commit checks).

Could you elaborate on that? What pre-commit checks? Could we move that to a separate PR?

@mathjazz mathjazz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well done!

Left some suggestions for minor improvements inline.

We'll also need to update the docs:
https://pontoon.mozilla.org/docs/localizer/users/?h=sett#appearance

</span>
{% endmacro %}

{% macro editor_button(user, long_name=True) %}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried just using one macro for both widgets?


.failed-checks .warning:before {
color: var(--grey-3);
color: var(--status-warning);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: that will also require a docs screenshot update. 😅
https://pontoon.mozilla.org/docs/localizer/translate/#warnings

Comment on lines +42 to +43
border: 1px solid var(--main-border-1);
border-radius: 3px;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make the field look like on PROD and like the main input field:

Suggested change
border: 1px solid var(--main-border-1);
border-radius: 3px;
border: none;

color: var(--editor-color);
float: left;
font-size: 14px;
height: 24px;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're at it, let's also fix the height to match the label:

Suggested change
height: 24px;
height: 26px;

And for the buttons (.translationform .accesskeys .key), set it like this:

line-height: 24px;
width: 26px;

</div>
{{ ThemeToggle.button(user) }}
<div class="field theme-field">
<p class="theme-label">Main</p>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<p class="theme-label">Main</p>
<p class="theme-label">Main interface</p>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<p class="theme-label">Main</p>
<p class="theme-label">Main app</p>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, also use "Match main interface/app" in the Editor widget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support dark theme in editor

3 participants