-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContentLanguagesLanguageRepo.ts
31 lines (26 loc) · 1.14 KB
/
ContentLanguagesLanguageRepo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import LanguageRepository from '@/common/data-access/LanguageRepository';
import LanguageCollection from '@/datamodel/LanguageCollection';
import WikibaseContentLanguagesRepo from './WikibaseContentLanguagesRepo';
import RtlDetectLib from 'rtl-detect';
export default class ContentLanguagesLanguageRepo implements LanguageRepository {
private languagesRepo: WikibaseContentLanguagesRepo;
public constructor( languageRepo: WikibaseContentLanguagesRepo ) {
this.languagesRepo = languageRepo;
}
public getLanguages(): Promise<LanguageCollection> {
return this.languagesRepo.getContentLanguages( null )
.then( ( contentLanguages ) => {
const languages: LanguageCollection = {};
Object.entries( contentLanguages ).forEach( ( [ languageCode, _language ] ) => {
languages[ languageCode ] = {
code: languageCode,
// this does not do full justice to the directionality question
// * languages do not have directionality - scripts do
// * the configured wikibase instance may have more/different languages
directionality: RtlDetectLib.getLangDir( languageCode ),
};
} );
return languages;
} );
}
}