@@ -20,7 +20,7 @@ const _proxy = process.env.CORS_PROXY || '';
20
20
* @type {string }
21
21
* @private
22
22
*/
23
- const _endpoint = `${ _host } /common/v18/js/data/jsononly/locale` ;
23
+ const _endpoint = `${ _proxy } ${ _host } /common/v18/js/data/jsononly/locale` ;
24
24
25
25
/**
26
26
* Locale API class with method of fetching user's locale for
@@ -59,7 +59,7 @@ class LocaleAPI {
59
59
const lc = lang . split ( '-' ) [ 0 ] ;
60
60
61
61
if ( cc && lc ) {
62
- const list = await this . getList ( ) ;
62
+ const list = await this . getList ( cc , lc ) ;
63
63
const verifiedCodes = this . verifyLocale ( cc , lc , list ) ;
64
64
65
65
// set the ipcInfo cookie
@@ -73,6 +73,9 @@ class LocaleAPI {
73
73
/**
74
74
* Get the country list of all supported countries and their languages
75
75
*
76
+ * @param {string } cc country code
77
+ * @param {string } lc language code
78
+ *
76
79
* @returns {Promise <any> } promise object
77
80
*
78
81
* @example
@@ -82,16 +85,24 @@ class LocaleAPI {
82
85
* const list = await LocaleAPI.getList();
83
86
* }
84
87
*/
85
- static async getList ( ) {
86
- const url = `${ _proxy } ${ _endpoint } /usen-locale.json` ;
87
-
88
+ static async getList ( cc , lc ) {
88
89
return await axios
89
- . get ( url , {
90
+ . get ( ` ${ _endpoint } / ${ cc } ${ lc } -locale.json` , {
90
91
headers : {
91
92
'Content-Type' : 'application/json; charset=utf-8' ,
92
93
} ,
93
94
} )
94
- . then ( response => response . data ) ;
95
+ . then ( response => response . data )
96
+ . catch ( async ( ) => {
97
+ //default to us-en locale if previous call fails
98
+ return await axios
99
+ . get ( `${ _endpoint } /usen-locale.json` , {
100
+ headers : {
101
+ 'Content-Type' : 'application/json; charset=utf-8' ,
102
+ } ,
103
+ } )
104
+ . then ( response => response . data ) ;
105
+ } ) ;
95
106
}
96
107
97
108
/**
0 commit comments