Numeric fields can have a prefix or suffix. These are defined in both singular and plural form. When the field is shown on a page the suffix gets translated using the format_plural() function (this is done in the number_field_formatter_view() function). However, on the edit form, this prefix or suffix is not translated, it is just filtered (using function field_filter_xss())and displayed (this happens in function number_field_widget_form()).
Aside from the fact that other field properties are translated via contrib, this is not consistent and considered an error. To solve this in D7, I guess that we have to use t() for prefix/suffix on the edit form as format_plural does so on showing the field.
In D8, the situation will be completely different.
Comment | File | Size | Author |
---|---|---|---|
#21 | 1220964-21.patch | 15.03 KB | neetu morwani |
Comments
Comment #1
fietserwinAttached a patch that uses t() (as outlined in the problem summary).
Comment #3
yched CreditAttribution: yched commentedt() is not meant to be called on user-entered data, that is the realm of http://drupal.org/project/i18n.
Translation of field properties is handled by the i18n_field module.
It's rather a bug in number.module that number_field_formatter_view() runs the prefixes and suffixes through format_plural(). We need to use our own non-t() logic in there.
I guess something like the attached patch. This does not support languages with more than one plural form, but :
- I don't think the current code (straight from the CCK era) does either - at least not officially. The help text for the 'prefix' and 'suffix settings reads : "Define a string that should be suffixed to the value. Separate singular and plural values with a pipe ('pound|pounds')".
- At this time in the night, I can't seem to make any sense of the logic behind multi-plural languages inside format_plural() anyway.
In other words, opinions from i18n / locale people welcome :-)
Comment #4
sunmmm, I don't want to sound bitchy, but the added inline comment documents a fact or bug that shouldn't have existed in the first place (common knowledge)... -- whereas I have an extremely hard time to figure out what that effin' $index logic is actually doing, but there's no comment for that... ;)
10 days to next Drupal core point release.
Comment #5
fietserwinHaving a 2nd look at the code of format_plural and it turns out it is quite easy to circumvent the use of format_plural. Because what we want to know is what plural form to use. That is not as easy as looking at the value (1 = singular , other = plural) because there are languages where it is much more complicated than that (see e.g. http://www.gnu.org/s/hello/manual/gettext/Plural-forms.html). But within format_plural this logic is outsourced to locale_get_plural(). Thus the number_field module should use locale_get_plural() itself to get the "plural form index".
Note as there are languages that have more than 2 plural forms, the code should just check if the index is within range.
More notes:
- i18n_field must translate before explode()'ing the prefix/suffix string as a user entered string with 2 plural forms can lead to a prefix/suffix string with 3 or 4 entries in another language. I'm not sue if i18n_field is already doing anything with prefix/suffix. If not I will create an issue in the i18n queue.
- The "plural form index" should perhaps be better explained in the documentation of function locale_get_plural. I will create a separate issue for that as I think it should be renamed to locale_get_plural_form_index and that code contains superfluous return statements.
Comment #6
fietserwinCreated issue #1221208: i18n_field should translate prefix/suffix of number fields in i18n queue.
Comment #7
fietserwinThis issue depends on completion of #1221276: locale_get_plural() only works for a single language within a request and does not work for English.
Comment #8
sunThis remix, of directly accessing and using locale information in the global language object to handle and output plural forms of user input, requires architectural discussion.
Comment #9
fietserwinPatch contained 2 lines to initialize $index, reposting a new one.
@todo: if locale_get_plural() won't return -1 anymore (see issue #1221276: locale_get_plural() only works for a single language within a request and does not work for English) this code can be further cleaned-up. Not sure if I should put this todo in the patch?
@sun: how is the global language object involved? (Other than not using the $langcode passed in, which seems to be the wrong way to go assuming the patch in #1216772: Field allowed values are shown untranslated is correct.)
Comment #10
sunComment #11
fietserwinI get it and your arguments explain why the errors only pop up now and were not discovered earlier. But, looking forward, what does this mean for the process to follow? Accept a kind of dirty fix for D7 and subsequently address it properly within the D8MI initiative (which is an accepted backport workflow)? Or do you want it properly solved in D7 as well?
Comment #12
Gábor HojtsyYes, I theoretically agree that given that we assume the site setting is in the default site language, we should use the plural rules for the default site language. Looks like the easiest way out would be to fix locale_get_plural() to work with English as well.
Comment #13
sunPostponing on #1221276: locale_get_plural() only works for a single language within a request and does not work for English -- there's a working patch over there, just needs tests to get RTBC.
Comment #14
Gábor HojtsyAdding UI language translation tag.
#1221276: locale_get_plural() only works for a single language within a request and does not work for English is nearing completion, please review there! Thanks!
Comment #15
Gábor HojtsyTagging for the content handling leg of D8MI (too).
Comment #16
Gábor Hojtsy@all: #1221276: locale_get_plural() only works for a single language within a request and does not work for English just landed in Drupal 8, so we can continue fixing this one! Yay!
Comment #17
jair CreditAttribution: jair commentedNeeds reroll
Comment #18
amateescu CreditAttribution: amateescu commentedComment #19
danylevskyiComment #20
danylevskyiComment #21
neetu morwani CreditAttribution: neetu morwani commentedRerolled the patch #9.
Comment #23
biro.botond CreditAttribution: biro.botond commented21: 1220964-21.patch queued for re-testing.
Comment #24
biro.botond CreditAttribution: biro.botond commentedComment #25
Alumei CreditAttribution: Alumei commentedThis was resolved for 8.x as part of #1785748: Field formatters as plugins although it propably still needs a backport to 7.x.
Comment #26
mgiffordThis still a concern in D8? Unassigned issue too.
Comment #39
quietone CreditAttribution: quietone at PreviousNext commentedI tested this on 9.4.x, standard install, and was not able to reproduce this error. On the edit form, the prefix and suffix are now translated.
Therefore, closing as cannot reproduce. If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").
Thanks!