@@ -2,8 +2,8 @@ import '../utils/i18nHtml'
22
33import  {  iframeResize  }  from  'iframe-resizer' 
44
5- import  {  isAutoRuntimeInstallSupported  }  from  '../utils' 
6- import  {  getMessage  }  from  '../utils/i18n' 
5+ import  {  isAutoRuntimeInstallSupported ,   PREF_LOCALE  }  from  '../utils' 
6+ import  {  getAllLocales ,   getCurrentLocale ,   getMessage  }  from  '../utils/i18n' 
77
88const  iframeResizer  =  iframeResize ( { } ,  '#connector-instructions' ) [ 0 ] . iFrameResizer 
99
@@ -159,3 +159,23 @@ async function startWizard () {
159159} 
160160
161161startWizard ( ) 
162+ 
163+ /***************************** 
164+  Language Switcher 
165+  ****************************/ 
166+ 
167+ async  function  handleLanguageSwitcher  ( )  { 
168+   const  languageElement  =  document . getElementById ( 'setup-language' ) 
169+   const  languageNames  =  new  Intl . DisplayNames ( [ 'en' ] ,  {  type : 'language' ,  languageDisplay : 'standard'  } ) 
170+   const  allLocales  =  getAllLocales ( ) . map ( code  =>  [ languageNames . of ( code ) ,  code ] ) . sort ( ( a ,  b )  =>  a [ 0 ] . localeCompare ( b [ 0 ] ,  'en' ) ) 
171+   const  currentLocale  =  await  getCurrentLocale ( ) 
172+   for  ( const  [ name ,  code ]  of  allLocales )  { 
173+     languageElement . append ( new  Option ( name ,  code ,  code  ===  currentLocale ,  code  ===  currentLocale ) ) 
174+   } 
175+   languageElement . addEventListener ( 'change' ,  async  function  ( )  { 
176+     await  browser . storage . local . set ( {  [ PREF_LOCALE ] : this . value  } ) 
177+     window . location . reload ( ) 
178+   } ) 
179+ } 
180+ 
181+ handleLanguageSwitcher ( ) 
0 commit comments