Make content language data available to VE

We have a use case in which the client needs to be able to use
language utilities in the content language (footnote markers), so the
data must be wired through.  This will only be done in VE, and in the
special case that the interface language != the content language.

Bug: T369613
Change-Id: I2c10e1e36ba594da98e0efa433dd9e1a25aae6fe
This commit is contained in:
Adam Wight 2024-07-09 13:09:03 +02:00
parent e22dc3c08b
commit 08969af51c
2 changed files with 34 additions and 1 deletions

View file

@ -117,7 +117,11 @@
"ve.ui.MWCitationContextItem.js",
"ve.ui.MWCitationAction.js",
"ve.ui.MWReference.init.js",
"ve.ui.MWCitationNeededContextItem.js"
"ve.ui.MWCitationNeededContextItem.js",
{
"name": "ve.ui.contentLanguage.js",
"callback": "Cite\\ResourceLoader\\ContentLanguage::makeScript"
}
],
"styles": [
"ve.ui.MWReferenceDialog.less",

View file

@ -0,0 +1,29 @@
<?php
namespace Cite\ResourceLoader;
use MediaWiki\MediaWikiServices;
use MediaWiki\ResourceLoader as RL;
/**
* Callback to deliver language data for the content language, if different than the interface language.
*
* @copyright 2024 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
* @license MIT
*/
class ContentLanguage {
public static function makeScript( RL\Context $context ): string {
$contentLang = MediaWikiServices::getInstance()->getContentLanguage();
$contentLangCode = $contentLang->getCode();
$interfaceLangCode = $context->getLanguage();
if ( $contentLangCode === $interfaceLangCode ) {
return '';
}
return 'mw.language.setData('
. $context->encodeJson( $contentLangCode ) . ','
. $context->encodeJson( $contentLang->getJsData() )
. ');';
}
}