@@ -12,59 +12,89 @@ export const schema = gql`
1212 Presence, e.g. 'Netflix'
1313 """
1414 presence: StringOrStringArray
15- ): [Language!]!
15+ ): [PresenceLanguage!]!
16+ }
17+
18+ type PresenceLanguage {
19+ """
20+ Presence, e.g. 'Netflix'
21+ """
22+ presence: String!
23+ """
24+ The available languages for the presence
25+ """
26+ languages: [Language!]!
1627 }
1728` ;
1829
1930export async function resolver (
2031 _ : any ,
2132 args : {
22- presence ? : string | string [ ] ;
33+ presence : string | string [ ] ;
2334 } ,
2435 { dataSources : { strings } } : { dataSources : { strings : Strings } }
2536) {
26- const fetchedStrings = await strings . get ( args ) ,
27- englishStrings = fetchedStrings . find ( s => s . lang === "en-US" ) ?? {
28- translations : { }
29- } ,
30- // String count of the English strings by first name
31- englishStringCount : {
32- [ key : string ] : number ;
33- } = { } ;
37+ args . presence = Array . isArray ( args . presence )
38+ ? args . presence
39+ : [ args . presence ] ;
3440
35- for ( const key of Object . keys ( englishStrings . translations ) ) {
36- const [ firstName ] = key . split ( "." ) ;
37- englishStringCount [ firstName ] = ( englishStringCount [ firstName ] ?? 0 ) + 1 ;
38- }
41+ const returnObject : {
42+ [ service : string ] : {
43+ lang : string ;
44+ nativeName : string ;
45+ direction : "ltr" | "rtl" ;
46+ } [ ] ;
47+ } = { } ;
3948
40- return fetchedStrings
41- . filter ( s => {
42- const fetchedStringCount : {
49+ for ( const presence of args . presence ) {
50+ const fetchedStrings = await strings . get ( { presence } ) ,
51+ englishStrings = fetchedStrings . find ( s => s . lang === "en-US" ) ?? {
52+ translations : { }
53+ } ,
54+ // String count of the English strings by first name
55+ englishStringCount : {
4356 [ key : string ] : number ;
4457 } = { } ;
4558
46- for ( const key of Object . keys ( s . translations ) ) {
47- const [ firstName ] = key . split ( "." ) ;
48- fetchedStringCount [ firstName ] =
49- ( fetchedStringCount [ firstName ] ?? 0 ) + 1 ;
50- }
59+ for ( const key of Object . keys ( englishStrings . translations ) ) {
60+ const [ firstName ] = key . split ( "." ) ;
61+ englishStringCount [ firstName ] = ( englishStringCount [ firstName ] ?? 0 ) + 1 ;
62+ }
63+
64+ returnObject [ presence ] = fetchedStrings
65+ . filter ( s => {
66+ const fetchedStringCount : {
67+ [ key : string ] : number ;
68+ } = { } ;
69+
70+ for ( const key of Object . keys ( s . translations ) ) {
71+ const [ firstName ] = key . split ( "." ) ;
72+ fetchedStringCount [ firstName ] =
73+ ( fetchedStringCount [ firstName ] ?? 0 ) + 1 ;
74+ }
5175
52- // Check if the fetched language has 60% of the strings translated per first name
53- for ( const firstName of Object . keys ( englishStringCount ) ) {
54- const sixtyPercent = englishStringCount [ firstName ] * 0.6 ;
76+ // Check if the fetched language has 60% of the strings translated per first name
77+ for ( const firstName of Object . keys ( englishStringCount ) ) {
78+ const sixtyPercent = englishStringCount [ firstName ] * 0.6 ;
5579
56- if (
57- ! ( firstName in fetchedStringCount ) ||
58- fetchedStringCount [ firstName ] < sixtyPercent
59- )
60- return false ;
61- }
80+ if (
81+ ! ( firstName in fetchedStringCount ) ||
82+ fetchedStringCount [ firstName ] < sixtyPercent
83+ )
84+ return false ;
85+ }
86+
87+ return true ;
88+ } )
89+ . map ( s => ( {
90+ lang : s . lang ,
91+ nativeName : s . nativeName ,
92+ direction : s . direction
93+ } ) ) ;
94+ }
6295
63- return true ;
64- } )
65- . map ( s => ( {
66- lang : s . lang ,
67- nativeName : s . nativeName ,
68- direction : s . direction
69- } ) ) ;
96+ return Object . entries ( returnObject ) . map ( ( [ presence , languages ] ) => ( {
97+ presence,
98+ languages
99+ } ) ) ;
70100}
0 commit comments