diff --git a/pontoon/administration/forms.py b/pontoon/administration/forms.py index b549daf643..1f9b16989f 100644 --- a/pontoon/administration/forms.py +++ b/pontoon/administration/forms.py @@ -38,9 +38,10 @@ class ProjectForm(forms.ModelForm): def clean(self): cleaned_data = super().clean() + set_locales_from_repo = cleaned_data.get("set_locales_from_repo") locales_readonly = cleaned_data.get("locales_readonly") locales = cleaned_data.get("locales") - if not (locales or locales_readonly): + if not (set_locales_from_repo or locales or locales_readonly): raise ValidationError("At least one locale must be selected.") class Meta: @@ -61,6 +62,8 @@ class Meta: "sync_disabled", "tags_enabled", "pretranslation_enabled", + "set_locales_from_repo", + "set_translated_resources_from_repo", "visibility", ) diff --git a/pontoon/administration/static/css/admin_project.css b/pontoon/administration/static/css/admin_project.css index ad3ba79a78..0e3a5ad86e 100644 --- a/pontoon/administration/static/css/admin_project.css +++ b/pontoon/administration/static/css/admin_project.css @@ -178,12 +178,20 @@ form a:visited { margin: 5px 9px; } +.controls .save { + width: 150px !important; +} + .controls .checkbox { float: left; margin: -1px 20px 0 0; text-transform: uppercase; } +.locales { + margin-top: 40px; +} + .double-list-selector .locale.select .menu { background: transparent; border-bottom: 1px solid var(--main-border-1); diff --git a/pontoon/administration/static/js/admin_project.js b/pontoon/administration/static/js/admin_project.js index 4b19493a2d..0c096873be 100644 --- a/pontoon/administration/static/js/admin_project.js +++ b/pontoon/administration/static/js/admin_project.js @@ -76,8 +76,9 @@ $(function () { button.addClass('in-progress').html('Syncing...'); + const slug = $('#id_slug').val(); $.ajax({ - url: '/admin/projects/' + $('#id_slug').val() + '/sync/', + url: `/admin/projects/${slug}/sync/`, success: function () { button.html('Started'); }, @@ -105,8 +106,9 @@ $(function () { button.addClass('in-progress').html('Pretranslating...'); + const slug = $('#id_slug').val(); $.ajax({ - url: '/admin/projects/' + $('#id_slug').val() + '/pretranslate/', + url: `/admin/projects/${slug}/pretranslate/`, success: function () { button.html('Started'); }, @@ -166,6 +168,51 @@ $(function () { }); }); + const setLocalesCheckbox = $('#id_set_locales_from_repo'); + const configFileInput = $('#id_configuration_file'); + function setLocalesUpdate() { + const configFile = configFileInput.val(); + let reqSync = configFile !== configFileInput.data('init'); + + const controls = $('.repo-locale-control'); + if ($('#id_data_source').val() === 'repository') { + controls.show(); + } else { + controls.hide(); + setLocalesCheckbox.prop('checked', false); + reqSync = false; + } + + const label = $('#id_set_locales_from_repo + span'); + const hint = $('#hint_set_locales_from_repo'); + if (configFile) { + label.text('Read locales from configuration file'); + hint.hide(); + } else { + label.text('Set locales from repository'); + hint.show(); + } + + const setLocalesFromRepo = setLocalesCheckbox.prop('checked'); + const trDiv = $('#translated_resources_from_repo'); + const locales = $('.locales, .locales-toolbar'); + if (setLocalesFromRepo) { + trDiv.toggle(!configFile); + locales.hide(); + reqSync ||= setLocalesFromRepo !== setLocalesCheckbox.data('init'); + } else { + trDiv.hide(); + locales.show(); + } + + $('button.save').text(reqSync ? 'Save & sync project' : 'Save project'); + } + setLocalesCheckbox.data('init', setLocalesCheckbox.prop('checked')); + setLocalesCheckbox.on('change', setLocalesUpdate); + configFileInput.data('init', configFileInput.val()); + configFileInput.on('change', setLocalesUpdate); + setLocalesUpdate(); + self.NProgressUnbind(); // Set locales to existing projects to be copied to the current project diff --git a/pontoon/administration/templates/admin_project.html b/pontoon/administration/templates/admin_project.html index 55dfcddaff..cbcd143f02 100644 --- a/pontoon/administration/templates/admin_project.html +++ b/pontoon/administration/templates/admin_project.html @@ -54,7 +54,29 @@

Locales

-
+
+ + Locale is available if target directory is present. +
+ + + +