Page MenuHomePhabricator

Untranslated unit div’s break list
Closed, DeclinedPublic

Description

When an untranslated unit is inside a list, the following code is generated:

* <div lang="en" dir="ltr" class="mw-content-ltr">
A text which has not been translated yet.
</div>

Which is parsed like this:

<ul><li><div lang="en" dir="ltr" class="mw-content-ltr"></div></li></ul>
<p>A text which has not been translated yet.
</p>

You can check this real example on Meta-Wiki (see unit just next “Step 5” unit).

I think the easiest way to solve this is to remove the carriage return after the div opening tag to avoid any new line which would break the wikitext list syntax.

Introduced with: T254484: Tag untranslated translations units with lang and dir attributes

Event Timeline

Nikerabbit triaged this task as Medium priority.Sep 28 2020, 6:30 AM
Nikerabbit added a project: Documentation.
Nikerabbit added a subscriber: Nikerabbit.

It chooses div vs. span depending on whether there is a newline inside the tags. If the newline was removed after the tag, the following mark-up would not render correctly:

<translate>
* text here
</translate>

https://www.mediawiki.org/wiki/Help:Extension:Translate/Page_translation_administration should explain this, but it doesn't currently.

Indeed, other untranslated units in list don’t meet this issue.

So, I should tag the page like this:

* <translate>Step 5</translate>
** <translate>This is a list item content.</translate>

<translate>
This is no more a list content.
</translate>

instead of following tagging which I used to limit translate tag use:

* <translate>Step 5</translate>
** <translate>This is a list item content.

This is no more a list content.
</translate>

Am I right?

Am I right?

Yes, and it is also more future proof.

By the way, should we mark every translate tags inside list as inline tags?

Previously we commonly used to split lists like that:

<translate>
* first item
* second item
* another item
</translate>
<translate>
* The same list continues with long elements which are eventually isolated in their own translate tag.
</translate>
<translate>
* We usually kept list bullet point inside translation unit.
</translate>

Should we now ever add translate inside list items for big lists, like the following?

* <translate>first item</translate>
* <translate>second item</translate>
* <translate>another item</translate>
* <translate>The same list continues with long elements which are eventually isolated in their own translate tag.</translate>
* <translate>We usually kept list bullet point inside translation unit.</translate>

Or is there any plan to detect list units and add lang and dir attribute to li instead of adding a div tag?

There are no immediate plans to change how list items work. For now it's best to tag either the whole list as one unit, or each item separately as inline units, or if you really want to split to bigger chunks, you can of course use the nowrap option.

For long term we may consider some convenience feature for lists that would reduce the amount of markup needed.

With the new style of the lists (meh, the [tens of] hours I have spent fixing it to what the previous revision of the documentation said) does translation preview in TUX still render units as list items?

For long term we may consider some convenience feature for lists that would reduce the amount of markup needed.

How difficult is this to do?

@Nikerabbit, could you point to the piece of code that does the following please?

It chooses div vs. span depending on whether there is a newline inside the tags.

Is it

extensions/Translate/tag/TPSection.php:201
		if ( $this->canWrap() && $attributes ) {
			$tag = $this->isInline() ? 'span' : 'div';
			$content = $this->isInline() ? $content : "\n$content\n";
			$content = Html::rawElement( $tag, $attributes, $content );
		}

? I assume this works with the source of the translation page and then it is regular MW parser that proceeds it and outputs final HTML?

That's the part which generates the wikitext for the parser on translation pages.

To summarize: these options are valid and do not break:

A
<translate>
* List item
* List item
</translate>

B
<translate nowrap>
* List item
* List item
</translate><translate nowrap>
* List item
* List item
</translate>

C
* <translate>List item</translate>
* <translate>List item</translate>