-
-
Notifications
You must be signed in to change notification settings - Fork 976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement pluralized add new translation string on web UI #11756
Implement pluralized add new translation string on web UI #11756
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #11756 +/- ##
==========================================
- Coverage 90.82% 90.62% -0.20%
==========================================
Files 554 577 +23
Lines 57306 58856 +1550
Branches 9122 9395 +273
==========================================
+ Hits 52046 53340 +1294
- Misses 3640 3824 +184
- Partials 1620 1692 +72
|
2ae47ab
to
9cc3dd4
Compare
529dcc8
to
f4fd982
Compare
a1a44b0
to
e09a29b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I've made some minor comments.
weblate/lang/models.py
Outdated
@@ -663,6 +663,10 @@ def is_base(self, vals: tuple[str, ...]) -> bool: | |||
"""Detect whether language is in given list, ignores variants.""" | |||
return self.base_code in vals | |||
|
|||
def get_source_plurals(self): | |||
"""Return blank source fields for pluralized new string.""" | |||
return ["" for _ in range(self.plural.number)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ["" for _ in range(self.plural.number)] | |
return [""] * self.plural.number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied the recommended change in the code.
weblate/templates/translation.html
Outdated
</a> | ||
<ul class="dropdown-menu"> | ||
<li><a href="#new-singular" data-toggle="tab">{% trans "Singular" %}</a></li> | ||
<li><a href="#new-plural" data-toggle="tab">{% trans "Plural" %}</a></li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the plural choice should be available only for languages having plural (plural.number > 1). Otherwise, there would be two same forms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, updated the code the new plural translation string. The form for new plural string and those buttons that leads it will be only shown if plural.number > 1
.
cc0c79d
to
30577f8
Compare
@@ -74,9 +74,6 @@ | |||
{% endif %} | |||
<li><a href="{% url 'data_project' project=object.component.project.slug %}">{% trans "Data exports" %}</a></li> | |||
<li><a href="{% url 'checks' path=object.get_url_path %}">{% trans "Failing checks" %}</a></li> | |||
{% if user_can_add_unit %} | |||
<li><a href="#new" data-toggle="tab">{{ object.component.get_add_label }}</a></li> | |||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really prefer to keep it this way so that link to #new
still works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted to the previous #new
hyperlink to a tab containing the new Add new translation string form.
weblate/templates/translation.html
Outdated
{% endif %} | ||
</ul> | ||
</li> | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The top-level navigation has already enough items, so better to stick with placement in the Tools menu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted this change.
</div> | ||
</form> | ||
</div> | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have it on a single tab and toggle the forms there (maybe radio)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, It is now only a single tab. The form can be switched by selecting Singular
or Plural
radio buttons.
weblate/lang/models.py
Outdated
@@ -663,6 +663,10 @@ def is_base(self, vals: tuple[str, ...]) -> bool: | |||
"""Detect whether language is in given list, ignores variants.""" | |||
return self.base_code in vals | |||
|
|||
def get_source_plurals(self): | |||
"""Return blank source fields for pluralized new string.""" | |||
return [""] * self.plural.number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default language plural doesn't have to be the one which is actually being used, this should belong to the Translation
class to get correct Plural
instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transferred the function get_source_plurals
to Translation
model.
def get_new_unit_form(translation, user, data=None, initial=None): | ||
def get_new_unit_form( | ||
translation, user, data=None, initial=None, is_source_plural=None | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that is_source_plural
should be passed in all branches here, not just the one. Currently, the Singular and Plural forms are the same for me on monolingual translation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added is_source_plural
to NewMonolingualUnitForm
to address this.
30577f8
to
2c0e098
Compare
weblate/trans/forms.py
Outdated
data=data, | ||
initial=initial, | ||
is_source_plural=is_source_plural, | ||
) | ||
return NewBilingualUnitForm(translation, user, data=data, initial=initial) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured this out, both source
and target
in the NewBilingualUnitForm
must receive the value of is_source_plural
.
$("#new-singular").addClass("hidden"); | ||
$("#new-plural").removeClass("hidden"); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this also sync forms content? So that the text doesn't disappear when you toggle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this can now transfer the inputs when toggling between the singular and plural forms.
Tests need some adjustment:
Most likely, the failures are for formats not supporting plurals so the tests should assert that plurals do not work in that case? See https://github.com/WeblateOrg/weblate/actions/runs/9583865006/job/26426111254?pr=11756 |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
….get_source_plurals
for more information, see https://pre-commit.ci
1b8c139
to
8b114d8
Compare
Hi @nijel, I can't directly reply on your comment about the test failure. I adjusted the test to skip those formats that are not supported. |
Merged, thanks for your contribution! |
<label class="radio-inline"> | ||
<input type="radio" name="new-unit-form-type" id="show-singular" value="singular" checked> {% trans "Singular" %} | ||
</label> | ||
<label class="radio-inline"> | ||
<input type="radio" name="new-unit-form-type" id="show-plural" value="plural" | ||
{% if object.plural.number < 2 %} disabled{% endif %}> {% trans "Plural" %} | ||
</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These radios should be hidden if there is just a single form available (show only if {% if object.plural.number > 1 %}
).
Proposed changes
This changes the way how the adding of new translation string done in the web UI.
This adds an option to add pluralized translation string.
This solves issue #7663.
Example image:
![Screenshot 2024-06-18 at 23-38-58 Test Project_Test Component — English @ Devel Weblate](https://private-user-images.githubusercontent.com/20557045/340741843-58866bd7-049a-44a2-ad96-309bacbf3249.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE0MTg1NDUsIm5iZiI6MTcyMTQxODI0NSwicGF0aCI6Ii8yMDU1NzA0NS8zNDA3NDE4NDMtNTg4NjZiZDctMDQ5YS00NGEyLWFkOTYtMzA5YmFjYmYzMjQ5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE5VDE5NDQwNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThjZTFkMWE4MjkzMWVmYTRlYWY3ZTE3N2NiN2IwN2E1YzAxOGUxZThkYjY1YWY3NWFmMTkyYjVlZDA4NWMyOWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.XEAFMvCmykgmH-llJruBYyodvbQ8s0hpfMppb8uZ_NM)
Checklist
Other information