Skip to content

Commit

Permalink
Replace wikibase-monolingualtext message with hard-coded HTML
Browse files Browse the repository at this point in the history
No language actually customized this message, and expecting them to
duplicate the full HTML markup is silly anyways. Instead, hard-code the
HTML structure in MonolingualHtmlFormatter, and use MediaWiki’s existing
messages to localize the language-dependent element: the space between
text and language name, and the parentheses around the language name.
(In e.g. Chinese, the space is blank and the parentheses are fullwidth.)

Bug: T361005
Change-Id: I0b98a79d308a1d1fc648cf25ad4445ba4adf06fb
  • Loading branch information
lucaswerkmeister committed Dec 18, 2024
1 parent 4c0fba2 commit f05a00c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"wikibase-time-precision-BCE-millennium": "$1. millennium BCE",
"wikibase-time-precision-BCE-century": "$1. century BCE",
"wikibase-time-precision-BCE-10annum": "$1s BCE",
"wikibase-monolingualtext": "<span lang=\"$2\" class=\"wb-monolingualtext-value\">$1</span> <span class=\"wb-monolingualtext-language-name\" dir=\"auto\">($3)</span>",
"wikibase-snakformatter-valuetype-mismatch": "The value's type \"$1\" does not match Property's type \"$2\".",
"wikibase-snakformatter-property-not-found": "Property $1 not found, cannot determine the data type to use.",
"wikibase-snakformatter-formatting-exception": "Formatting error: $1.",
Expand Down
1 change: 0 additions & 1 deletion lib/i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
"wikibase-time-precision-BCE-millennium": "Used to present a point in time BCE (before current era) with the precision of 1000 years. $1 is the millennium, given as year rounded up to the next 1000 and divided by 1000.\n{{Related|Wikibase-time-precision}}",
"wikibase-time-precision-BCE-century": "Used to present a point in time BCE (before current era) with the precision of 100 years. $1 is the century, given as year rounded up the next hundred and divided by 100.\n{{Related|Wikibase-time-precision}}",
"wikibase-time-precision-BCE-10annum": "Used to present a point in time BCE (before current era) with the precision of 10 years. $1 is the point in time in years, rounded down to the nearest ten.\n{{Related|Wikibase-time-precision}}",
"wikibase-monolingualtext": "{{optional}}\nFormat for displaying monolingual text (along with a language name).\n\nParameters:\n* $1 - the text\n* $2 - the code of the language of the text\n* $3 - the name of the language of the text, in the user's language.",
"wikibase-snakformatter-valuetype-mismatch": "Warning shown when if the data value type used by a Snak's (see [[d:Wikidata:Glossary]]) property's data type is different from the type of the Snak's actual value.\n\nParameters:\n* $1 - data value type of the property-value Snak's value.\n* $2 - data value type used by the data type used in the property which is used by the property-value Snak",
"wikibase-snakformatter-property-not-found": "Warning shown when a Snak's (see [[d:Wikidata:Glossary]]) data type could not be determined based on the Snak's property ID.",
"wikibase-snakformatter-formatting-exception": "Warning shown when a Snak (see [[d:Wikidata:Glossary]]) could not be rendered due to an internal error (a FormattingException).\n* $1 - the error message from the FormattingException, in English, possibly including technical details.",
Expand Down
21 changes: 16 additions & 5 deletions lib/includes/Formatters/MonolingualHtmlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DataValues\MonolingualTextValue;
use InvalidArgumentException;
use MediaWiki\Html\Html;
use MediaWiki\Language\LanguageCode;
use ValueFormatters\ValueFormatter;
use Wikibase\Lib\LanguageNameLookup;
Expand Down Expand Up @@ -40,11 +41,21 @@ public function format( $value ) {
$languageCode = $value->getLanguageCode();
$languageName = $this->languageNameLookup->getName( $languageCode );

return wfMessage( 'wikibase-monolingualtext',
wfEscapeWikiText( $text ),
wfEscapeWikiText( LanguageCode::bcp47( $languageCode ) ),
wfEscapeWikiText( $languageName )
)->parse();
return Html::element(
'span',
[
'lang' => LanguageCode::bcp47( $languageCode ),
'class' => 'wb-monolingualtext-value',
],
$text
) . wfMessage( 'word-separator' )->escaped() . Html::rawElement(
'span',
[
'class' => 'wb-monolingualtext-language-name',
'dir' => 'auto',
],
wfMessage( 'parentheses' )->plaintextParams( $languageName )->parse()
);
}

}

0 comments on commit f05a00c

Please sign in to comment.