ULS i18n performance fixes
* Since there is an API to load the i18n json files, avoid sending list of localizations to client. Previously this list was used to avoid 404s for json files. Now API takes care of it. Remove the caching for this list too. * Preload the i18n files on document ready. This avoids delay in initializing IME or ULS window after fetch i18n from server. * ApiULSLocalization can serve messages for all namespaces known if namespace parameter is not set Bug: 50391 Change-Id: I6b848da35f57353790bf460983cdf19a11bb238a
This commit is contained in:
@@ -34,22 +34,25 @@ class ApiULSLocalization extends ApiBase {
|
||||
$this->dieUsage( 'Invalid language', 'invalidlanguage' );
|
||||
}
|
||||
|
||||
if ( $namespace === 'uls' ) {
|
||||
$filename = "lib/jquery.uls/i18n/$language.json";
|
||||
} else {
|
||||
$filename = "i18n/$language.json";
|
||||
$contents = array();
|
||||
// jQuery.uls localization
|
||||
if ( !$namespace || $namespace === 'uls' ) {
|
||||
$filename = __DIR__ . "/../lib/jquery.uls/i18n/$language.json";
|
||||
if ( file_exists( $filename ) ) {
|
||||
$contents += json_decode( file_get_contents( $filename ), true );
|
||||
}
|
||||
}
|
||||
// mediaWiki.uls localization
|
||||
if ( !$namespace || $namespace === 'ext-uls' ) {
|
||||
$filename = __DIR__ . "/../i18n/$language.json";
|
||||
if ( file_exists( $filename ) ) {
|
||||
$contents += json_decode( file_get_contents( $filename ), true );
|
||||
}
|
||||
}
|
||||
// Output the file's contents raw
|
||||
$this->getResult()->addValue( null, 'text', json_encode( $contents ) );
|
||||
$this->getResult()->addValue( null, 'mime', 'application/json' );
|
||||
|
||||
$localPath = __DIR__ . "/../$filename";
|
||||
if ( !file_exists( $localPath ) ) {
|
||||
$this->getResult()->addValue( null, 'text', '{}' );
|
||||
$this->getResult()->addValue( null, 'mime', 'application/json' );
|
||||
} else {
|
||||
$contents = file_get_contents( $localPath );
|
||||
// Output the file's contents raw
|
||||
$this->getResult()->addValue( null, 'text', $contents );
|
||||
$this->getResult()->addValue( null, 'mime', 'application/json' );
|
||||
}
|
||||
}
|
||||
|
||||
public function getCustomPrinter() {
|
||||
@@ -68,7 +71,6 @@ class ApiULSLocalization extends ApiBase {
|
||||
'namespace' => array(
|
||||
ApiBase::PARAM_TYPE => 'string',
|
||||
ApiBase::PARAM_REQUIRED => false,
|
||||
ApiBase::PARAM_DFLT => 'ext-uls',
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -76,7 +78,7 @@ class ApiULSLocalization extends ApiBase {
|
||||
public function getParamDescription() {
|
||||
return array(
|
||||
'language' => 'Language string',
|
||||
'namespace' => 'Namespace string.',
|
||||
'namespace' => 'Namespace string. If not given loads messages for all namespaces known',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user