Problem/Motivation
Following the introduction to plural sources in #2453761: Views numeric formatter's plural formatting setting incompatible with many languages, config translation needs to support exposing a user interface to display singular/plural sources and plural targets. It does support translating those now so long as users carefully insert EXT (\x03) manually between the variants, which is a no-go in terms of UX.
Proposed resolution
Implement UI similar to TranslateEditForm::buildForm().
Remaining tasks
Review.
User interface changes
Singular/plural sources would show properly, targets would provide multiple input fields appropriate for the language.
Multiple sources when translating from Slovenian to Russian:
Singular only when translating from Vietnamese to Irish:
The plural forms labels from this last screenshot should be corrected by #2499639: Use correct labels for numeric fields when using a multiple plural forms language.
API changes
1. Added a new config schema type: 'plural_string'
2. Added a new config translation form element: 'PluralString'
Beta phase evaluation
Issue category | Bug because of bad UX |
---|---|
Issue priority | Major because of bad UX |
Unfrozen changes | Unfrozen because it only changes the user interface of configuration translation of plural strings |
Prioritized changes | The main goal of this issue is usability |
Disruption | Not disruptive |
Comment | File | Size | Author |
---|---|---|---|
#66 | interdiff.txt | 3.33 KB | maxocub |
#66 | plural_strings_translation-2454829-65.patch | 15 KB | maxocub |
#63 | interdiff.txt | 4.78 KB | maxocub |
#63 | plural_strings_translation-2454829-63.patch | 15.01 KB | maxocub |
#63 | test_only.patch | 3.68 KB | maxocub |
Comments
Comment #1
Gábor Hojtsy#2453761: Views numeric formatter's plural formatting setting incompatible with many languages landed.
Comment #2
Gábor HojtsyPut on sprint in hopes that we can get to start work on this. I'll not be able to personally devote time to drive this in the foreseeable future :/ Can help with reviews. Practically this issue needs to resolve these two @todos:
Comment #3
rvilarI'm working on it
Comment #4
rvilarAttached is a first approach to this feature.
Now I have the problem that I need to create a submit function for the form to process the values for plural configuration translation to add the LOCALE_PLURAL_DELIMITER before save the current configuration. What could be the better approach to do that?
Comment #5
rvilarAdded the tag for devdays review
Comment #7
fran seva CreditAttribution: fran seva commentedComment #8
Jose Reyero CreditAttribution: Jose Reyero commentedIt seems we need to be able to provide not only a text widget that handles these locale delimiters, but one that spawns into a different number of text fields depending on the language we are translating to.
So I think simply hacking around current form elements just won't work. We need to provide a new data type / widget for handling these strings, which may be interesting just to see how well our current config translation API supports other widgets.
These are the pieces we'd need to implement:
1. New config schema type.. 'plural_string' (that will extend 'string' and be 'translatable')
2. A new config translation form element... 'PluralString'
Btw, seeing the current views.field.numeric schema, it seems we are not thinking of other translatable elements, like Thousands marker, Prefix, Suffix, etc... shouldn't we translate those too? Wondering whether we should be adding a full 'number format' schema type somewhere instead of just 'plural_string'....
Comment #9
maxocub CreditAttribution: maxocub commentedThanks for your insight Jose Reyero. Last week I made a patch that support multiple plural forms, but didn't post it since it was too hackish and I haven't find how to save the config anyway.
I agree with you about the need to create a new type / widget, I'll try that this weekend.
Comment #10
Gábor Hojtsy@Jose Reyero: The prefix and suffix are already translatable on numeric fields, the decimal point and separator are not, that is in itself easy to fix (making them "label"s). Introducing a more high level type to support for translation as a whole is a whole new question not in scope for this issue IMHO. The plural translation solution has beenfits other than the numeric fields in views.
Comment #11
maxocub CreditAttribution: maxocub commentedHere is a first patch where I add the new data type.
For now, I justed copied the Textfield widget to see if it worked.
I will continue to work to build the widget for this new type.
@Gábor Hojtsy, @Jose Reyero, can you tell me if I'm on the right track?
I'm not sure about the naming of things, please tell me if there's better names, comments, etc.
Comment #12
maxocub CreditAttribution: maxocub commentedComment #13
Jose Reyero CreditAttribution: Jose Reyero commented@maxocub,
Yes, that's the idea. Now you only need to implement the FormElement class which I'm afraid will be the most complex part.
About the names I'd like more 'plural_string / PluralString' and it can extend 'string' (type: string, translatable:true) because it may not be really a 'label'.
Comment #14
maxocub CreditAttribution: maxocub commentedComment #15
maxocub CreditAttribution: maxocub commentedThis is still not a final patch, it's just to get some review.
So I found a way to implement the FormElement class, and I'd like to know what you think about it, @Jose Reyero.
Visually it's not perfect, since using a fieldset adds a border and a background that doesn't match between source and translation, but essentially, it seems to work.
Comment #16
maxocub CreditAttribution: maxocub commentedHere's what it looks like:
Comment #17
maxocub CreditAttribution: maxocub commentedHere's an updated patch where I add titles to the fieldsets and generate only one plural form source element.
I've found that with the previous patch, when we translate from a multiple plural forms language to a single one (like from Slovenian to English), we have multiple source elements for only one translation element. I looked at how it's done in TranslateEditForm::buildForm() and did the same here to always have one sigular form and one plural form in the source element.
Is that what is expected?
Comment #18
eiriksmI think this looks good. I would set it to RTBC, but it would need a test, no?
Wrote a quick test (which is the only difference compared to the patch in #17).
Comment #19
maxocub CreditAttribution: maxocub commentedThanks eiriksm for the test, that was the next thing I was going to do.
Should we add more tests for when we have multiple plural forms?
Also, I'd like to update the patch to remove the 'TODOs' from FormElementBase:
And remove a useless array index:
I'll do that tonight.
Comment #21
eiriksmI don't see why that could hurt :)
The only reason I did not add that (and the actual checking of translations being saved and displayed) is that #2453761: Views numeric formatter's plural formatting setting incompatible with many languages adds a whole lot of tests for the functionality of translating the strings. Just not through the interface. But that was my thought, what do you guys think?
Comment #22
Gábor Hojtsy@eiriksm: re #21 we are adding support to the UI here, so we should test the UI IMHO.
Comment #23
vijaycs85Looks like it's 'needs review'
Comment #25
maxocub CreditAttribution: maxocub commentedI think it was still on 'Needs work' because the test eiriksm added failed, but I don't know why. I ran it localy and it passed. Also, I was thinking about adding more tests for languages with multiple plural forms, but I haven't had the time yet.
Comment #26
eiriksmI posted a test-only patch (which by the way was the one that just was re-queued for testing). This test was meant to fail, as it shows it needs the patch to pass. Perhaps meaningless in the context of adding a new feature, still it shows the value the test was providing (namely test a new feature, that did not exist).
So when this test is run, it will also fail.
The first patch on the other hand, will pass (hopefully) as it includes the test and the patch provided by @maxocub :)
Comment #27
maxocub CreditAttribution: maxocub commentedOh, silly me, I haven't thought about that, of course it failed! Thanks @eiriksm!
Comment #29
maxocub CreditAttribution: maxocub commentedComment #30
penyaskitoI think we need a test translating to a language with multiple plurals. Direction of the patch looks good :))
Aside of that:
Nitpicking, should fit in 80 chars.
We should use @ here for the placeholders.
We should use SafeMarkup::format.
We also need before/after screenshots in the issue summary.
Comment #31
maxocub CreditAttribution: maxocub commented1) Made the changes from #19 & #30
2) Modified the test from #18 to use a multiple plural forms language
3) Added before/after screenshots to the summary
Comment #32
maxocub CreditAttribution: maxocub commentedComment #33
eiriksmLGTM!
Patch works and screenshots are descriptive.
Comment #34
penyaskitoWhat I expected was having #markup in the format. Actually wondering if it should be an inline template instead.
It feels weird having:
- First plural form
- 2 plural form
Could we improve that? Not sure if really possible.
Thanks for working on this one!
Comment #35
maxocub CreditAttribution: maxocub commented@penyaskito, the PluralString FormElement was based on the TranslateEditForm::buildForm() as proposed in the summary, your comments then apply to this one too.
1)
Not sure I understand here.
2)
If we do, we should do it to the TranslateEditForm::buildForm() too (see image below).
Shouldn't we do that in a new issue?
Comment #36
penyaskito1. I see TranslateEditForm is mixing inline templates and string concatenation (see line 102). I guess we can leave this for a follow-up. What I meant is having all the HTML in the SafeMarkup::format() call.
2. Let's create a follow-up then for that too.
So we still need:
1. Create those follow-ups.
2. Add the beta-evaluation template
Comment #37
maxocub CreditAttribution: maxocub commentedOK, I'll do those two things this weekend.
Should I correct the SafeMarkup::format() first or do I leave it for the follow-up?
Comment #38
penyaskitoLeave it for the follow-up, so we have same in both forms.
Hope that committers agree and we can RTBC this one.
Comment #39
maxocub CreditAttribution: maxocub commentedUpdated the summary and added the beta evaluation template.
Comment #40
maxocub CreditAttribution: maxocub commentedOpened two follow-up issues: #2499639: Use correct labels for numeric fields when using a multiple plural forms language and #2499651: Use inline_templates in TranslateEditForm::buildForm() and PluralString::getTranslationElement()
Comment #41
penyaskitoFor me this is RTBC now. Thanks for your continuous effort, @maxocub!
Comment #42
alexpottThis looks odd. Why are we using
SafeMarkup::format()
here.This shouldn't be
t()
'd everything has already been translated. UseSafeMarkup::format
instead.This is deprecated. We shouldn't be adding usages. Use
\Drupal::service('file_system')->unlink()
instead. However I'm not sure why we're doing this as the file should be cleaned up after the test anyway.Comment #43
maxocub CreditAttribution: maxocub commentedComment #45
Gábor HojtsyDoes not seem to be a related fail.
Comment #47
penyaskitoBack to RTBC, feedback was addressed.
We could change SafeMarkup for inline templates while we are editing those lines, but let's try to do that in follow-up #2499651: Use inline_templates in TranslateEditForm::buildForm() and PluralString::getTranslationElement(). I tagged that one with SafeMarkup for visibility.
Comment #48
alexpottWhat happens when a site is installed in a language which has more plural forms?
Comment #49
maxocub CreditAttribution: maxocub commentedWhen a site is installed in a language with multiple plural forms, only the singular and one plural form are displayed on the source side. At first, I tried to display all of them, but I think it makes no sense for two reasons:
Since formatPlural() take as arguments $count, $singular and $plural, I think it's logical to only show the singular and one plural form, and when #2499639: Use correct labels for numeric fields when using a multiple plural forms language will be resolved, it will make this form a lot clearer.
Also, this form was based upon TranslateEditForm::buildForm(), which have the same behavior.
Comment #50
Gábor Hojtsy@maxocub: well, formatPlural() is supposed to be used with English source strings only. Configuration may or may not be originally in English. It may have from 1 (eg. Vietnamese) to 5 (eg. Irish) or even 6 (eg. Arabic) variants depending on language. So displaying exactly two forms may or may not even work. The source display AFAIS should use the same code to display variants as the form input code does.
Comment #51
maxocub CreditAttribution: maxocub commented@Gábor Hojtsy: OK, I see, I will change that, but is it the case only for configuration translation or should we do the same thing with TranslateEditForm::buildForm() ?
Comment #52
Gábor HojtsyIn TranslateEditForm / locale module / formatPlural(), the source is always English, at least unless someone misuses the API, so the source always uses two plural forms. In configuration, the source may be any language, so there may be 1 to 6 variants (as opposed to a fixed 2) both in the source and the target. See eg. #2453761: Views numeric formatter's plural formatting setting incompatible with many languages which is a form for editing original configuration with a plural setting. That has the varied plural input for the config value too.
Comment #53
maxocub CreditAttribution: maxocub commentedUpdated patch with as many source elements as the source language's plural forms.
Here's what it looks like when translating from Slovenian to Russian:
And from Vietnamese to Irish:
Since Vietnamese doesn't have a plural form, formatPlural on the labels returns 'First plural form' for every translation elements (I think). This problem should be solved by #2499639: Use correct labels for numeric fields when using a multiple plural forms language, but it's postponed on this issue. What should we do? Make a temporary fix here before solving #2499639: Use correct labels for numeric fields when using a multiple plural forms language, or postpone this issue and fix #2499639: Use correct labels for numeric fields when using a multiple plural forms language first?
Comment #54
Gábor HojtsyI know @reyero prefered plural_string as the type name, but I indicated that if we consider this a special case of label (which it is), then it should be plural_label. Not all strings that we use the 'label' type for are actual labels, but the label type is translatable, the string type is not. The plural_string type makes it look like this is a derivative of strings, while its more logically a derivative of labels. (Feel free to actually inherit it from label too).
Let's get this on one line if we can. Eg. "Defines form elements for plurals in configuration translation."
I think this displays the incorrect plural labels because you are not passing over the language to use for the plural logic. I see TranslateEditForm and NumericField have the same code. So these will not be good :D We can either try to argue around it here and ignore the problem and solve it in #2499639: Use correct labels for numeric fields when using a multiple plural forms language or solve it here but then the scope would expand :(
So I feel like better would be to solve in #2499639: Use correct labels for numeric fields when using a multiple plural forms language. However, the solution is not just changing text but also changing logic, because we need to send over the right language to use for the plural variant *selection* but not for translating the item. So it would properly say "3. plural form" even if English (the UI language used to display it) does not support a 3rd plural.
One way to do that would be to do $this->t('First plural form' . LOCALE_PLURAL_DELIMITER . '@count. plural form') (do not pass in a langcode, so the translation happens to the interface) and then $this->formatPluralTranslated() and pass in the langcode there, so the right logic is picked. That would fall down if the translation replaces "@count plural form" with "Plural variant" or something though...
Anyway, I see this is an existing problem in the code copied around 3rd time now, so I am inclined to defer to #2499639: Use correct labels for numeric fields when using a multiple plural forms language. Let's add a @todo at least then referring to there above the two formatPlural() lines, so we track it.
Finally, the issue summary needs updating with new screenshots.
Comment #55
Gábor HojtsyOh, this label is also pre-existing, but it looks silly if you look at the UI (this patch is the first fixing this UI, so let's fix it here). If you look at Vietnamese screenshot its evidently wrong, there is only one form, not "singular and one or more plural". So maybe "Plural variants" or something would be better.
Comment #56
maxocub CreditAttribution: maxocub commentedComment #57
maxocub CreditAttribution: maxocub commented#54/1: I replace 'plural_string' by 'plural_label'. I also replaced the widget's name from 'PluralString' to 'PluralVariants', I hope it's OK.
#54/2: I changed the doc string to 'Defines form elements for plurals in configuration translation.'
#54/3: I added the @todos in PluralVariants::getSourceElement(), PluralVariants::getTranslationElement(), NumericField::buildOptionsForm(), and TranslateEditForm::buildForm().
#55: I changed the label to 'Plural Variants'.
Comment #58
Gábor HojtsyYay, let's get this in then and refine labels in #2499639: Use correct labels for numeric fields when using a multiple plural forms language.
Comment #59
alexpottThe manual testing of the changes in #53 looks great but afaics we didn't extend the automated test coverage for this.
Comment #60
Gábor Hojtsy@Maxocub: can you work on this one still?
Comment #61
maxocub CreditAttribution: maxocub commented@Gábor Hojtsy: Absolutely, I just had no time last week, and sorry about missing the meeting.
Comment #62
tstoecklerI might be totally on crack, but I can't seem to fathom where to find this function anywhere?
I think the
<span class="visually-hidden"%gt;
should be in the fieldset#title
so it is next to the field name, like it is for other fields.This should not be necessary, but should already be set in the form, no?
The effect is the same, but I would find the code more readable if we did
$element[$i]
instead of$element[]
. It just looks very non-standard to have form elements without an explicit key.Missing "g" in
@lancode
All of theses also apply to
getTranslationElement()
Comment #63
maxocub CreditAttribution: maxocub commented#59: I added a test to check the number of plural strings' source elements.
Now I'm going to address @tstoeckler's comments from #62.
Comment #64
maxocub CreditAttribution: maxocub commentedComment #66
maxocub CreditAttribution: maxocub commented@tstoeckler:
#62/1: It's in core/lib/Drupal/Core/StringTranslation/TranslationManager.php line 246
#62/2: I moved it to the fieldset.
#62/3: I don't think it is set on the form since the config doesn't get saved if I remove it.
EDIT: From core/modules/config_translation/src/Form/ConfigTranslationFormBase.php line 165:
#62/4: I added the index to the $element.
#62/5: Corrected.
Thanks for the review!
Comment #67
tstoecklerGreat find on the
#tree
usage. I had totally forgotten about that, thanks for the explanation!Test coverage looks totally sufficient now from my perspective.
I found last thing, that we should fix before this can be committed:
Just like
FormElementBase
this should use$this->t()
on the outer level, i.e. instead of theSafeMarkup::format()
.Comment #68
Gábor Hojtsy@tstoeckler: not sure about that format/t, there is nothing translatable in the text it is only used for formatting with some HTML. The patch has several of those and @alexpot complained in #42 that it was a t() and said it should be safemarkup format :D
Comment #69
tstoecklerHmm... I disagree, but more importantly, as noted above,
FormElementBase
contains the same code already. In any case, let's not hold this up on such a minor detail, we can always improve, and even if we don't no one should lose sleep over this.RTBC.
Comment #70
alexpott@tstoeckler I think FormElementBase is weird. Translators have enough to do without translating things like
'!label <span class="visually-hidden">(!source_language)</span>'
... if this needs to be altered then it should be a template.Committed 77b9dbc and pushed to 8.0.x. Thanks!
Comment #72
Gábor HojtsyYay, amazing! Now we just need #2499639: Use correct labels for numeric fields when using a multiple plural forms language fixed :)
Comment #73
tstoecklerAs always, you make a very good point. I like that idea! Might open a ticket for that if I get around to it. In any case, thanks @everyone, especially @maxocub: Impressive persistence here!!! yay
Comment #74
maxocub CreditAttribution: maxocub commentedThanks! About the templates, there's already #2499651: Use inline_templates in TranslateEditForm::buildForm() and PluralString::getTranslationElement() that could be modified to include FormElementBase.
Comment #76
maxocub CreditAttribution: maxocub commentedComment #77
maxocub CreditAttribution: maxocub as a volunteer and commented