File tree Expand file tree Collapse file tree 2 files changed +6
-11
lines changed Expand file tree Collapse file tree 2 files changed +6
-11
lines changed Original file line number Diff line number Diff line change @@ -6,3 +6,4 @@ declare module '*.svg' {
6
6
const content : string ;
7
7
export default content ;
8
8
}
9
+ declare function gettext ( s : string ) : string ;
Original file line number Diff line number Diff line change @@ -4,7 +4,8 @@ import {StyleHelpers} from './helpers';
4
4
import { countries } from './countries' ;
5
5
import styles from './PhoneNumber.scss' ;
6
6
7
- declare function gettext ( s : string ) : string ;
7
+ const gettext = typeof window . gettext === 'function' ? window . gettext : ( ( s : string ) => s ) ;
8
+
8
9
9
10
class PhoneNumberField {
10
11
private readonly inputElement : HTMLInputElement ;
@@ -60,16 +61,9 @@ class PhoneNumberField {
60
61
}
61
62
62
63
private createCountriesMap ( ) : [ string , CountryCallingCode , CountryCode ] [ ] {
63
- if ( typeof gettext === 'function' ) {
64
- return getCountries ( ) . map (
65
- countryCode => [ gettext ( countries . get ( countryCode ) ?? '' ) , getCountryCallingCode ( countryCode ) , countryCode ]
66
- ) ;
67
- } else {
68
- // gettext is not available in the global scope, so we use the country names as-is
69
- return getCountries ( ) . map (
70
- countryCode => [ countries . get ( countryCode ) ?? '' , getCountryCallingCode ( countryCode ) , countryCode ]
71
- ) ;
72
- }
64
+ return getCountries ( ) . map (
65
+ countryCode => [ gettext ( countries . get ( countryCode ) ?? '' ) , getCountryCallingCode ( countryCode ) , countryCode ]
66
+ ) ;
73
67
}
74
68
75
69
private createTextBox ( ) {
You can’t perform that action at this time.
0 commit comments