Skip to content

Commit

Permalink
Component: Rename toggle for adding new units
Browse files Browse the repository at this point in the history
It should affect removal as well, so give it better name.
  • Loading branch information
nijel committed Jan 29, 2021
1 parent e3df69a commit cce8aec
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 26 deletions.
20 changes: 12 additions & 8 deletions docs/admin/projects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -557,21 +557,25 @@ Disable adding new translations

:ref:`adding-translation`.

.. _component-new_unit:
.. _component-manage_units:

Adding new strings
++++++++++++++++++
Manage strings
++++++++++++++

Configures whether users in Weblate will be allowed to add new strings. Adjust
this to match your localization workflow - how the new strings are supposed to
be introduced.
Configures whether users in Weblate will be allowed to add new strings and
remove existing ones. Adjust this to match your localization workflow - how the
new strings are supposed to be introduced.

For bilingual formats, the strings are typically extracted from the source code
(for example by using :program:`xgettext`) and adding new strings in Weblate
should be disabled (they would be discarded next time you update the translation files).
should be disabled (they would be discarded next time you update the
translation files). In Weblate you can manage strings for every translation and
it does not enfornce the strings in all translations to be consistent.

For monolingual formats, the strings are added to the source language and that
makes it automatically translatable in all the translations.
makes it automatically translatable in all the translations. The strings are
managed only on source language and are automatically added or removed in the
translations.

.. seealso::

Expand Down
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ Translations

.. seealso::

:ref:`component-new_unit`,
:ref:`component-manage_units`,
:ref:`adding-new-strings`

.. http:post:: /api/translations/(string:project)/(string:component)/(string:language)/autotranslate/
Expand Down
2 changes: 1 addition & 1 deletion docs/devel/integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ new strings into Weblate.

.. note::

Availability of adding strings in Weblate depends on :ref:`component-new_unit`.
Availability of adding strings in Weblate depends on :ref:`component-manage_units`.

.. _updating-target-files:

Expand Down
6 changes: 3 additions & 3 deletions weblate/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class Meta:
"merge_message",
"addon_message",
"allow_translation_propagation",
"new_unit",
"manage_units",
"enable_suggestions",
"suggestion_voting",
"suggestion_autoaccept",
Expand Down Expand Up @@ -527,8 +527,8 @@ def fixup_request_payload(self, data):
)
if "project" in self._context:
data["project"] = self._context["project"]
if "new_unit" not in data:
data["new_unit"] = bool(data.get("template"))
if "manage_units" not in data:
data["manage_units"] = bool(data.get("template"))

def to_internal_value(self, data):
# Preprocess to inject params based on content
Expand Down
2 changes: 1 addition & 1 deletion weblate/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,7 @@ def test_add_bilingual(self):
request={"source": "Source", "target": "Target"},
code=403,
)
self.component.new_unit = True
self.component.manage_units = True
self.component.save()
self.do_request(
"api:translation-units",
Expand Down
2 changes: 1 addition & 1 deletion weblate/auth/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def check_unit_delete(user, permission, obj):
def check_unit_add(user, permission, translation):
component = translation.component
# Check if adding is generally allowed
if not component.new_unit or translation.is_readonly:
if not component.manage_units or translation.is_readonly:
return False
source = translation.is_source
template = component.has_template()
Expand Down
4 changes: 2 additions & 2 deletions weblate/trans/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ class Meta:
"restricted",
"auto_lock_error",
"links",
"new_unit",
"manage_units",
)
widgets = {
"enforced_checks": SelectChecksWidget,
Expand Down Expand Up @@ -1312,7 +1312,7 @@ def __init__(self, request, *args, **kwargs):
Fieldset(
_("Translation settings"),
"allow_translation_propagation",
"new_unit",
"manage_units",
"check_flags",
"variant_regex",
"enforced_checks",
Expand Down
27 changes: 27 additions & 0 deletions weblate/trans/migrations/0114_auto_20210129_1239.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.1.4 on 2021-01-29 12:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("trans", "0113_component_new_unit"),
]

operations = [
migrations.RenameField(
model_name="component",
old_name="new_unit",
new_name="manage_units",
),
migrations.AlterField(
model_name="component",
name="manage_units",
field=models.BooleanField(
default=False,
help_text="Disable adding and removing strings in Weblate in case these are automatically extracted from the source code or managed externally.",
verbose_name="Manage strings",
),
),
]
8 changes: 4 additions & 4 deletions weblate/trans/models/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,12 @@ class Component(FastDeleteModelMixin, models.Model, URLMixin, PathMixin, CacheKe
"translations created by Weblate."
),
)
new_unit = models.BooleanField(
verbose_name=gettext_lazy("Adding new strings"),
manage_units = models.BooleanField(
verbose_name=gettext_lazy("Manage strings"),
default=False,
help_text=gettext_lazy(
"Disable adding new strings in Weblate in case the strings "
"are automatically extracted from the source."
"Disable adding and removing strings in Weblate in case these "
"are automatically extracted from the source code or managed externally."
),
)

Expand Down
4 changes: 2 additions & 2 deletions weblate/trans/tests/test_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ def test_new_unit(self):
self.make_manager()

# No adding
self.component.new_unit = False
self.component.manage_units = False
self.component.save()
response = self.add_unit("key")
self.assertEqual(response.status_code, 403)

# Adding allowed (if format supports that)
self.component.new_unit = True
self.component.manage_units = True
self.component.save()
response = self.add_unit("key")
if not self.component.file_format_cls.can_add_unit:
Expand Down
4 changes: 2 additions & 2 deletions weblate/trans/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def _create_component(
kwargs["name"] = "Test"
kwargs["slug"] = kwargs["name"].lower()

if "new_unit" not in kwargs and template:
kwargs["new_unit"] = True
if "manage_units" not in kwargs and template:
kwargs["manage_units"] = True

if branch is None:
branch = VCS_REGISTRY[vcs].default_branch
Expand Down
2 changes: 1 addition & 1 deletion weblate/trans/views/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def detect_license(self, form):

def form_valid(self, form):
if self.stage == "create":
form.instance.new_unit = bool(form.instance.template)
form.instance.manage_units = bool(form.instance.template)
result = super().form_valid(form)
self.object.post_create(self.request.user)
return result
Expand Down

0 comments on commit cce8aec

Please sign in to comment.