Problem/Motivation

The string "second" in English can mean two different things:
- Unit of time (second, minute, hour)
- Ordinal number (first, second, third).

In some languages, such as German, the word "second" is translated differently depending on which meaning it has -- "Sekunde" for the time unit, and "zweite/r/s" for ordinal number.

In addition to that, ordinal numbers are adjectives, and so in many languages the translation depends on the noun's grammatical gender. For example, in German, you would use "zweiter" (m), "zweite" (f), or "zweites" (n). This also applies to other ordinal numbers (first, third, etc.).

Examples:

  • masculinum: second block - "zweiter Block"
  • femininum: second region - "zweite Region"
  • neutrum: second field - "zweites Feld"

So, when it is used in t() in Drupal, the bare word "Second", as well as other ordinal numbers, need translation context. See
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Language%...
for information about string context (scroll down the page to the section about context).

Currently, there is no translation context for these words in Drupal.

Proposed resolution

Add a context to all uses of the word "Second" in t(), where it might not be clear whether it means a time unit or an ordering, as well as to other ordinal numbers (first, third, etc.) to make it clear what they are ordering (for languages with gender).

For time units, the context string should be something like "time unit" or "datetime".

For ordinal numbers, it needs to be something like "block order", "field order", or similar.

Remaining tasks

  1. Novice task! Identify all applicable occurrences in Drupal core UI text of bare words "First", "Second", "Third", etc. (see note below) [This task can also be done for the other projects that have child issues -- see issue sidebar for a list of child issues]
  2. Decide on the right context string for each occurence
  3. Make a patch to add the strings. Note that for some YML files, the translation context may be added by the POTX process, so a patch of the POTX project may be necessary (see discussion about layout YAML files in comments on this issue).
  4. Do something similar for Drupal 7 and to other projects (in separate issues).

Further notes on task 1

  1. We are looking for the bare word "Second" or "second". For instance, this string does not need context:
    t('Second item')
    

    because it is pretty clear that it means second in order. But t('Second') by itself does need context. Also,

    t('Seconds'),
    

    does not need context, because it is plural and should be the unit of time in this case.

  2. The string can be found in:
    - YAML files
    - t() function calls

User interface changes

The string "Second", and other ordinal numbers, will be properly translatable in all contexts in all languages.

API changes

None.

Data model changes

None.

Release notes snippet

Issue fork drupal-3046985

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Joachim Namyslo created an issue. See original summary.

cilefen’s picture

Status: Active » Postponed (maintainer needs more info)

Can you give an example so we understand why this is a bug?

joachim namyslo’s picture

Issue summary: View changes

https://localize.drupal.org/translate/languages/de/translate?project=dru...

Not in screenshots right now.

But it is simple a second is not the same as a second block/item/etc. And because of that scond is often miss translated as

zweiter instead of Sekunde in German and maybe that's relevant for some other languages, too

First block
second block
third block

Erster Block
Zweiter Block
Dritter Block

will lead us to

Eine zweiter zuvor

instead of

Eine Sekunde zuvor.

Sorry to co maintainers. I used rocketchat and slack to notify them just because I wasn't able to find the documentation about how to report a context is needed.

This bug is existing since D5 or so and it seems we can't get it done.

joachim namyslo’s picture

Status: Postponed (maintainer needs more info) » Active
jhodgdon’s picture

Title: Context for second » The word "Second" needs translation context
Issue summary: View changes
Issue tags: +Novice

Let's see if we can get a novice contributor to work on this. Adding information to the issue summary.

cilefen’s picture

Oh, for translation! The original report did not specify.

jhodgdon’s picture

Issue summary: View changes

Adding more information to the issue summary.

Also a question: is it possible to add string context to YML files? For instance, I found the label 'Second' in
core/modules/layout_discovery/layout_discovery.layouts.yml
core/modules/layout_builder/layout_builder.layouts.yml (several instances)
and it would need a context in both of those files.

jhodgdon’s picture

Issue tags: +string context
m-schmitt’s picture

As for contexts in translations, I tried to revive an older issue and wrote a bit about that here:
https://www.drupal.org/project/drupal/issues/1035716
Unfortunately there were no responses, so I dropped it.
There is already a context:timeperiod here:
https://localize.drupal.org/translate/languages/de/translate?project&sta...
That is for the specific module Timeperiod, but I wonder if we couldn't use that as well to save an additional context and prevent bloating the list of contexts further. We also have some "date" contexts already.
Otherwise we need to figure out whether a broad context like "time" is fine for "second" or whether we would need something more specific. Additionally, there is the question whether to apply the context to all units of time (like "hour" and "day") or just strings that are obviously ambiguous.
As for the layouts, in my opinion those are fine. Because they clearly use "second" not as the unit of time, but as a number. Though clarifying that, might still be useful for some.

jhodgdon’s picture

To answer one of your questions: Context should only be added to words or phrases that might be ambiguous to translate. So there is no reason to add it to "hour" and "day".

As for the layouts, the problem is that the word "Second" will be run through the t() system from those layout labels. We need the context on all uses of the word "Second" to disambiguate each one as to whether it's the time unit or the numeric order word. Otherwise, the layout region might end up being called "The time unit of 1/60th of the minute" instead of "The second part of the layout". Which could be very weird in many languages. As if in English the regions of those layouts were called something like "First", "Hour", "Third". ?!?

berdir’s picture

We just added context to workflow transition/state labels, so that's definitely possible, see #3037906: Add translation contexts to workflow schema.

> To answer one of your questions: Context should only be added to words or phrases that might be ambiguous to translate. So there is no reason to add it to "hour" and "day".

That's the theory, but it's not so easy to know whether or not a word might require different translations, developers are often not aware, how could they. Typically this is a problem with single-word translations, so it might actually not be a stupid idea to recommend adding a context to them. But we would need to have some rules/documentation on how to structure those contexts, and it would IMHO also make sense to have a word with context fall back to the same word without context if there's no translation, discussed that a while ago with Gabor. As maybe only one language out of 10 (or 50?) will need to translate them differently..

darren oh’s picture

Issue tags: +Seattle2019
joachim namyslo’s picture

Maybe I am able to tag all 15 of them with novice issue untill you are awake.

If not use my post page to find them all

https://www.drupal.org/user/275771/track

Happy Codeing

joachim namyslo’s picture

Issue summary: View changes

Thank you @tobiasb

for providing an example

https://www.drupal.org/project/date_recur_modular/issues/3047243

hexabinaer’s picture

Issue summary: View changes

Correction of typos + adding clarificaion

hexabinaer’s picture

Issue summary: View changes

Amending own typo :-}

jhodgdon’s picture

Good clarification! It sounds like bare words of "First" and "Third" etc., if they exist in Core, also then need context -- and not just for German -- many non-English languages have gender. I imagine that those layout files have those in them, since they seem to have the word "Second" as a region name...

jhodgdon’s picture

One clarification... To add context to a YAML config file, it gets added to the corresponding schema. Example from #3037906: Add translation contexts to workflow schema:

# PHP Date format string that is translatable.
date_format:
 type: string
 label: 'Date format'
 translatable: true
 translation context: 'PHP date format'

So, if there is a string that needs translation context in a file that is in config/optional or config/install, you have to find the definition of the data schema in config/schema (which could be in this module or another project, or even in the core/config directory!), then add the translation context there.

But in this case, it isn't config, it is a layout YML file. So the only way to add translation context there is to find the definition of the translatable keys that is in the POTX project and add it there. Here is the file:
https://git.drupalcode.org/project/potx/blob/7.x-3.x/yaml_translation_pa...

It doesn't look like the layout files are even in that file though... so as far as I can tell, layout files do not generate translatable text for the POTX module, and their strings will not get onto localize.drupal.org currently.

Anyway... leaving this comment as it may be relevant for some of the child issues.

jhodgdon’s picture

I also created #3048032: Layout labels are not extracted for translation from layout.yml files to deal with the layout files, since that seems to be a sort of different/bigger issue.

dpi’s picture

What context are we going with here?

My suggestion is "ordinal", as in: first, second, third, etc. And "calendar" or "datetime", as in: "hours, minutes, second".

tatarbj’s picture

Issue tags: +DrupalCampBelarus2019
mradcliffe’s picture

Issue tags: +Amsterdam2019

Tagging for Amsterdam 2019

dpi’s picture

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jhodgdon’s picture

Issue summary: View changes

This issue has been sitting for 8 months while we try to decide on a good context.

The latest suggestion was #21... which seems good, except that for ordinal numbers "first" second" etc. we actually also need to know what they are applying to, because in many languages these adjectives also need gender.

So instead of a context that just says "ordinal", we actually need a specific context for each one. So for instance if it is "second" referring to the second footer region, then the context probably needs to be "ordinal for footer region" or something like that. The point is, we can have multiple words 'second' that are ordinal numbers, and depending on where they are being used, they might need different translations in different languages.

I think "datetime" for "second" when it is a unit of time is probably fine.

Also updating the issue summary about the other ordinal numbers.

krzysztof domański’s picture

Version: 8.8.x-dev » 8.9.x-dev
Issue tags: -Seattle2019, -DrupalCampBelarus2019, -Amsterdam2019 +String change in 8.9.0
jhodgdon’s picture

Issue summary: View changes

Adding some notes to the issue summary about the Novice task.

jhodgdon’s picture

Issue summary: View changes

additional note.

jhodgdon’s picture

Novice issue reserved for the Mentored Contribution during the Contribution Day at Europe2020. After the 11th December 2020, this issue returns to being open to all. Thanks

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
sanduhrs’s picture

StatusFileSize
new3.44 KB

find . -type f -not -path "*/vendor/*" -not -path "*/node_modules/*" -not -path "*/tests/*" -exec grep -li ": second" {} \;
25 matches in .yml files, with 22 false positives.

find . -type f -not -path "*/vendor/*" -not -path "*/node_modules/*" -not -path "*/tests/*" -exec grep -li "['\"]second['\"]" {} \;
13 matches in .php files, with 11 false positives.

Patch attached :)

sanduhrs’s picture

Status: Active » Needs review
StatusFileSize
new3.43 KB
sanduhrs’s picture

StatusFileSize
new4.43 KB

Adding additional context to regions labeled first, third, fourth, fifth as they need to be gendered in german.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bebalachandra’s picture

Status: Needs review » Needs work
StatusFileSize
new201.86 KB

patch #35 applied successfully. adding sample screenshot with this. Changing status to needs work so that any missing regions will be covered in upcoming work.

rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new14.59 KB
rpayanm’s picture

StatusFileSize
new4.43 KB

Sorry, wrong patch.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 200, following Review a patch or merge require as a guide.

Interesting bug!

Looks like the solution is good to go but this will need tests please.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone made their first commit to this issue’s fork.

quietone’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

I am not sure what is supposed to be tested here, so remove tag. I am sure it will be added back if needed.

Converted to an MR so setting for review.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

That's fair, I think the test tag was from our initial triage of 2900 issues to today. Think it's fine to not include tests.

Did search for t('Second') if there were other instances and appears to only be in tests, which don't need it.

LGTM

  • longwave committed b0d31368 on 11.x
    fix: #3046985 The word "Second" needs translation context
    
    By: jhodgdon...

  • longwave committed c8e47315 on main
    fix: #3046985 The word "Second" needs translation context
    
    By: jhodgdon...
longwave’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

I wonder if in a followup we could add something to core, Coder or PHPStan that detects known words that must have a context, and add at least "Second" to this list? (and perhaps all the ordinals, given the gender issue described here)

Committed and pushed c8e47315faf to main and b0d3136822f to 11.x. Thanks!

Not eligible for further backport as this will need re-translating in all languages now.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

berdir’s picture

We have an existing issue that also mentioned a phpcs check: #3108111: Require context for one word translatables, as mentioned there, I think we first need to change our context behavior so we can add contexts without breaking existing translations.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.