Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4112628
LanguageInfo.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
LanguageInfo.js
View Options
const
util
=
require
(
'./util.js'
),
actionParams
=
require
(
'./actionParams'
);
/**
* API for providing language data.
*
* @class module:mobile.startup/languages~LanguageInfo
* @param {mw.Api} api
*/
function
LanguageInfo
(
api
)
{
this
.
api
=
api
;
}
LanguageInfo
.
prototype
=
{
/**
* Get languageinfo API data from the local wiki, and transform it into a
* format usable by LanguageSearcher.
*
* @memberof module:mobile.startup/languages~LanguageInfo
* @instance
* @returns {jQuery.Deferred}
*/
getLanguages
()
{
return
this
.
api
.
get
(
actionParams
(
{
meta
:
'languageinfo'
,
liprop
:
'code|autonym|name|bcp47'
}
)
).
then
(
(
resp
)
=>
{
const
filteredLanguages
=
[];
// Filter out legacy languages and require an autonym.
// If the bcp47 (https://w.wiki/Y7A) does not match the language
// code, that is in an indication that the language code is outdated
// and should not be used.
Object
.
keys
(
resp
.
query
.
languageinfo
).
forEach
(
(
key
)
=>
{
const
language
=
resp
.
query
.
languageinfo
[
key
];
if
(
(
language
.
code
.
toLowerCase
()
===
language
.
bcp47
.
toLowerCase
()
)
&&
language
.
autonym
)
{
filteredLanguages
.
push
(
language
);
}
}
);
return
filteredLanguages
;
},
()
=>
util
.
Deferred
().
reject
()
).
then
(
(
filteredLanguages
)
=>
(
{
languages
:
filteredLanguages
.
map
(
(
data
)
=>
{
data
.
url
=
'#'
;
data
.
lang
=
data
.
code
;
data
.
langname
=
data
.
name
;
// FIXME: This isn't a "title" in the sense of a MediaWiki
// Title, and it is rendered as a subheader in the list
// item, so a different name would be wiser, both here and
// in LanguageSearcher's template. Also it would arguably
// be more intuitive for the language name (localized) to
// appear as the main emphasized element of each language
// list element; but instead the autonym has that role.
// A more thorough refactoring of LanguageSearcher to allow
// for generic header/subheader elements is left for a
// follow-up.
data
.
title
=
data
.
name
;
return
data
;
}
)
}
),
()
=>
util
.
Deferred
().
reject
()
);
}
};
module
.
exports
=
LanguageInfo
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Aug 18, 22:56 (14 h, 51 m ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f3/37/27f13b87a8f5e0886c8a50744136
Default Alt Text
LanguageInfo.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment