Skip to content

Commit 36fc460

Browse files
committed
Add setting to hide shared glossary components in projects they are shared to
1 parent a384316 commit 36fc460

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
@@ -1838,6 +1838,17 @@ for these default combinations.
18381838

18391839
Turn this off if you want to different translations for each variant.
18401840

1841+
.. setting:: HIDE_SHARED_GLOSSARY_COMPONENTS
1842+
1843+
HIDE_SHARED_GLOSSARY_COMPONENTS
1844+
-------------------------------
1845+
1846+
Glossary components are typically shared into other projects to
1847+
make them available for translation translation work.
1848+
When these are visible in the compnoent list of projects which are
1849+
using them, it can cause confusion or distract translators from
1850+
the actual components that are meant to be translated.
1851+
18411852
.. setting:: SITE_DOMAIN
18421853

18431854
SITE_DOMAIN

docs/admin/install/docker.rst

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

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

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

853857
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
@@ -1062,6 +1062,11 @@
10621062
# Use simple language codes for default language/country combinations
10631063
SIMPLIFY_LANGUAGES = get_env_bool("WEBLATE_SIMPLIFY_LANGUAGES", True)
10641064

1065+
# This allows to hide glossary components when shared to other projects
1066+
HIDE_SHARED_GLOSSARY_COMPONENTS = get_env_bool(
1067+
"WEBLATE_HIDE_SHARED_GLOSSARY_COMPONENTS", False
1068+
)
1069+
10651070
# Default number of elements to display when pagination is active
10661071
DEFAULT_PAGE_LIMIT = get_env_int("WEBLATE_DEFAULT_PAGE_LIMIT", 100)
10671072

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"
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)