Skip to content

Commit 73e77dc

Browse files
committed
Add setting to hide shared glossary components in projects they are shared to
1 parent 79eb342 commit 73e77dc

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

docs/admin/config.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,17 @@ for these default combinations.
18481848

18491849
Turn this off if you want to different translations for each variant.
18501850

1851+
.. setting:: HIDE_SHARED_GLOSSARY_COMPONENTS
1852+
1853+
HIDE_SHARED_GLOSSARY_COMPONENTS
1854+
-------------------------------
1855+
1856+
Glossary components are typically shared into other projects to
1857+
make them available for translation translation work.
1858+
When these are visible in the compnoent list of projects which are
1859+
using them, it can cause confusion or distract translators from
1860+
the actual components that are meant to be translated.
1861+
18511862
.. setting:: SITE_DOMAIN
18521863

18531864
SITE_DOMAIN

docs/admin/install/docker.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,10 @@ Generic settings
849849

850850
Configures the language simplification policy, see :setting:`SIMPLIFY_LANGUAGES`.
851851

852+
.. envvar:: WEBLATE_HIDE_SHARED_GLOSSARY_COMPONENTS
853+
854+
Hides glossary components when shared to other projects, see :setting:`HIDE_SHARED_GLOSSARY_COMPONENTS`.
855+
852856
.. envvar:: WEBLATE_DEFAULT_ACCESS_CONTROL
853857

854858
Configures the default :ref:`project-access_control` for new projects, see :setting:`DEFAULT_ACCESS_CONTROL`.

weblate/settings_docker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,11 @@
10551055
# Use simple language codes for default language/country combinations
10561056
SIMPLIFY_LANGUAGES = get_env_bool("WEBLATE_SIMPLIFY_LANGUAGES", True)
10571057

1058+
# This allows to hide glossary components when shared to other projects
1059+
HIDE_SHARED_GLOSSARY_COMPONENTS = get_env_bool(
1060+
"WEBLATE_HIDE_SHARED_GLOSSARY_COMPONENTS", False
1061+
)
1062+
10581063
# Default number of elements to display when pagination is active
10591064
DEFAULT_PAGE_LIMIT = get_env_int("WEBLATE_DEFAULT_PAGE_LIMIT", 100)
10601065

weblate/settings_example.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,9 @@
697697
# Use simple language codes for default language/country combinations
698698
SIMPLIFY_LANGUAGES = True
699699

700+
# This allows to hide glossary components when shared to other projects
701+
HIDE_SHARED_GLOSSARY_COMPONENTS = False
702+
700703
# Render forms using bootstrap
701704
CRISPY_ALLOWED_TEMPLATE_PACKS = ["bootstrap3", "bootstrap5"]
702705
CRISPY_TEMPLATE_PACK = "bootstrap3"

weblate/trans/views/basic.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
from collections import Counter
77
from typing import TYPE_CHECKING, Any
88

9+
from django.conf import settings
910
from django.contrib.auth.decorators import login_required
1011
from django.db import transaction
12+
from django.db.models import Q
1113
from django.http import HttpResponse
1214
from django.shortcuts import get_object_or_404, redirect
1315
from django.urls import reverse
@@ -373,9 +375,13 @@ def show_project(request: AuthenticatedHttpRequest, obj):
373375
last_changes = all_changes.recent()
374376
last_announcements = all_changes.filter_announcements().recent()
375377

376-
all_components = obj.get_child_components_access(
377-
user, lambda qs: qs.filter(category=None)
378-
)
378+
def filter_components(qs):
379+
qs = qs.filter(category=None)
380+
if settings.HIDE_SHARED_GLOSSARY_COMPONENTS:
381+
qs = qs.exclude(Q(is_glossary=True) & ~Q(project=obj))
382+
return qs
383+
384+
all_components = obj.get_child_components_access(user, filter_components)
379385
all_components = get_paginator(request, all_components, stats=True)
380386
for component in all_components:
381387
component.is_shared = None if component.project == obj else component.project

0 commit comments

Comments
 (0)