@lingo.dev/_locales 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +201 -0
- package/README.md +225 -0
- package/build/index.cjs +1033 -0
- package/build/index.d.cts +266 -0
- package/build/index.d.ts +266 -0
- package/build/index.mjs +994 -0
- package/package.json +34 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the components of a locale string
|
|
3
|
+
*/
|
|
4
|
+
interface LocaleComponents {
|
|
5
|
+
/** The language code (e.g., "en", "zh", "es") */
|
|
6
|
+
language: string;
|
|
7
|
+
/** The script code (e.g., "Hans", "Hant", "Cyrl") - optional */
|
|
8
|
+
script?: string;
|
|
9
|
+
/** The region/country code (e.g., "US", "CN", "RS") - optional */
|
|
10
|
+
region?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Locale delimiter types
|
|
14
|
+
*/
|
|
15
|
+
type LocaleDelimiter = "-" | "_";
|
|
16
|
+
/**
|
|
17
|
+
* Validation result for locale parsing
|
|
18
|
+
*/
|
|
19
|
+
interface ParseResult {
|
|
20
|
+
/** The parsed locale components */
|
|
21
|
+
components: LocaleComponents;
|
|
22
|
+
/** The delimiter used in the original string */
|
|
23
|
+
delimiter: LocaleDelimiter | null;
|
|
24
|
+
/** Whether the locale string was valid */
|
|
25
|
+
isValid: boolean;
|
|
26
|
+
/** Error message if parsing failed */
|
|
27
|
+
error?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Shared constants for locale parsing and validation
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Regular expression for parsing locale strings
|
|
35
|
+
*
|
|
36
|
+
* This regex is case-sensitive and expects normalized locale strings:
|
|
37
|
+
* - Language code: 2-3 lowercase letters (e.g., "en", "zh", "es")
|
|
38
|
+
* - Script code: 4 letters with preserved case (e.g., "Hans", "hans", "Cyrl")
|
|
39
|
+
* - Region code: 2-3 uppercase letters or digits (e.g., "US", "CN", "123")
|
|
40
|
+
*
|
|
41
|
+
* Matches locale strings in the format: language[-_]script?[-_]region?
|
|
42
|
+
*
|
|
43
|
+
* Groups:
|
|
44
|
+
* 1. Language code (2-3 lowercase letters)
|
|
45
|
+
* 2. Script code (4 letters, optional)
|
|
46
|
+
* 3. Region code (2-3 letters or digits, optional)
|
|
47
|
+
*
|
|
48
|
+
* Examples:
|
|
49
|
+
* - "en" -> language: "en"
|
|
50
|
+
* - "en-US" -> language: "en", region: "US"
|
|
51
|
+
* - "zh-Hans-CN" -> language: "zh", script: "Hans", region: "CN"
|
|
52
|
+
* - "sr_Cyrl_RS" -> language: "sr", script: "Cyrl", region: "RS"
|
|
53
|
+
*
|
|
54
|
+
* Note: The parser automatically normalizes case before applying this regex:
|
|
55
|
+
* - Language codes are converted to lowercase
|
|
56
|
+
* - Script codes preserve their original case
|
|
57
|
+
* - Region codes are converted to uppercase
|
|
58
|
+
*/
|
|
59
|
+
declare const LOCALE_REGEX: RegExp;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Breaks apart a locale string into its components
|
|
63
|
+
*
|
|
64
|
+
* @param locale - The locale string to parse
|
|
65
|
+
* @returns LocaleComponents object with language, script, and region
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* parseLocale("en-US"); // { language: "en", region: "US" }
|
|
70
|
+
* parseLocale("en_US"); // { language: "en", region: "US" }
|
|
71
|
+
* parseLocale("zh-Hans-CN"); // { language: "zh", script: "Hans", region: "CN" }
|
|
72
|
+
* parseLocale("zh_Hans_CN"); // { language: "zh", script: "Hans", region: "CN" }
|
|
73
|
+
* parseLocale("es"); // { language: "es" }
|
|
74
|
+
* parseLocale("sr-Cyrl-RS"); // { language: "sr", script: "Cyrl", region: "RS" }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function parseLocale(locale: string): LocaleComponents;
|
|
78
|
+
/**
|
|
79
|
+
* Parses a locale string and returns detailed information about the parsing result
|
|
80
|
+
*
|
|
81
|
+
* @param locale - The locale string to parse
|
|
82
|
+
* @returns ParseResult with components, delimiter, and validation info
|
|
83
|
+
*/
|
|
84
|
+
declare function parseLocaleWithDetails(locale: string): ParseResult;
|
|
85
|
+
/**
|
|
86
|
+
* Extracts just the language code from a locale string
|
|
87
|
+
*
|
|
88
|
+
* @param locale - The locale string to parse
|
|
89
|
+
* @returns The language code
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* getLanguageCode("en-US"); // "en"
|
|
94
|
+
* getLanguageCode("zh-Hans-CN"); // "zh"
|
|
95
|
+
* getLanguageCode("es-MX"); // "es"
|
|
96
|
+
* getLanguageCode("fr_CA"); // "fr"
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function getLanguageCode(locale: string): string;
|
|
100
|
+
/**
|
|
101
|
+
* Extracts the script code from a locale string
|
|
102
|
+
*
|
|
103
|
+
* @param locale - The locale string to parse
|
|
104
|
+
* @returns The script code or null if not present
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* getScriptCode("zh-Hans-CN"); // "Hans"
|
|
109
|
+
* getScriptCode("zh-Hant-TW"); // "Hant"
|
|
110
|
+
* getScriptCode("sr-Cyrl-RS"); // "Cyrl"
|
|
111
|
+
* getScriptCode("en-US"); // null
|
|
112
|
+
* getScriptCode("es"); // null
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
declare function getScriptCode(locale: string): string | null;
|
|
116
|
+
/**
|
|
117
|
+
* Extracts the region/country code from a locale string
|
|
118
|
+
*
|
|
119
|
+
* @param locale - The locale string to parse
|
|
120
|
+
* @returns The region code or null if not present
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* getRegionCode("en-US"); // "US"
|
|
125
|
+
* getRegionCode("zh-Hans-CN"); // "CN"
|
|
126
|
+
* getRegionCode("es"); // null
|
|
127
|
+
* getRegionCode("fr_CA"); // "CA"
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
declare function getRegionCode(locale: string): string | null;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Checks if a locale string is properly formatted and uses real codes
|
|
134
|
+
*
|
|
135
|
+
* @param locale - The locale string to validate
|
|
136
|
+
* @returns true if the locale is valid, false otherwise
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* isValidLocale("en-US"); // true
|
|
141
|
+
* isValidLocale("en_US"); // true
|
|
142
|
+
* isValidLocale("zh-Hans-CN"); // true
|
|
143
|
+
* isValidLocale("invalid"); // false
|
|
144
|
+
* isValidLocale("en-FAKE"); // false
|
|
145
|
+
* isValidLocale("xyz-US"); // false
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
declare function isValidLocale(locale: string): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Checks if a language code is valid
|
|
151
|
+
*
|
|
152
|
+
* @param code - The language code to validate
|
|
153
|
+
* @returns true if the language code is valid, false otherwise
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* isValidLanguageCode("en"); // true
|
|
158
|
+
* isValidLanguageCode("zh"); // true
|
|
159
|
+
* isValidLanguageCode("es"); // true
|
|
160
|
+
* isValidLanguageCode("xyz"); // false
|
|
161
|
+
* isValidLanguageCode("fake"); // false
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function isValidLanguageCode(code: string): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Checks if a script code is valid
|
|
167
|
+
*
|
|
168
|
+
* @param code - The script code to validate
|
|
169
|
+
* @returns true if the script code is valid, false otherwise
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* isValidScriptCode("Hans"); // true (Simplified Chinese)
|
|
174
|
+
* isValidScriptCode("Hant"); // true (Traditional Chinese)
|
|
175
|
+
* isValidScriptCode("Latn"); // true (Latin alphabet)
|
|
176
|
+
* isValidScriptCode("Cyrl"); // true (Cyrillic)
|
|
177
|
+
* isValidScriptCode("Fake"); // false
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
declare function isValidScriptCode(code: string): boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Checks if a region/country code is valid
|
|
183
|
+
*
|
|
184
|
+
* @param code - The region code to validate
|
|
185
|
+
* @returns true if the region code is valid, false otherwise
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* isValidRegionCode("US"); // true
|
|
190
|
+
* isValidRegionCode("CN"); // true
|
|
191
|
+
* isValidRegionCode("GB"); // true
|
|
192
|
+
* isValidRegionCode("ZZ"); // false
|
|
193
|
+
* isValidRegionCode("FAKE"); // false
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
declare function isValidRegionCode(code: string): boolean;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Gets a country name in the specified display language
|
|
200
|
+
*
|
|
201
|
+
* @param countryCode - The ISO country code (e.g., "US", "CN", "DE")
|
|
202
|
+
* @param displayLanguage - The language to display the name in (default: "en")
|
|
203
|
+
* @returns Promise<string> - The localized country name
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* // Default English
|
|
208
|
+
* await getCountryName("US"); // "United States"
|
|
209
|
+
* await getCountryName("CN"); // "China"
|
|
210
|
+
*
|
|
211
|
+
* // Spanish
|
|
212
|
+
* await getCountryName("US", "es"); // "Estados Unidos"
|
|
213
|
+
* await getCountryName("CN", "es"); // "China"
|
|
214
|
+
*
|
|
215
|
+
* // French
|
|
216
|
+
* await getCountryName("US", "fr"); // "États-Unis"
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
declare function getCountryName(countryCode: string, displayLanguage?: string): Promise<string>;
|
|
220
|
+
/**
|
|
221
|
+
* Gets a language name in the specified display language
|
|
222
|
+
*
|
|
223
|
+
* @param languageCode - The ISO language code (e.g., "en", "zh", "es")
|
|
224
|
+
* @param displayLanguage - The language to display the name in (default: "en")
|
|
225
|
+
* @returns Promise<string> - The localized language name
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```typescript
|
|
229
|
+
* // Default English
|
|
230
|
+
* await getLanguageName("en"); // "English"
|
|
231
|
+
* await getLanguageName("zh"); // "Chinese"
|
|
232
|
+
*
|
|
233
|
+
* // Spanish
|
|
234
|
+
* await getLanguageName("en", "es"); // "inglés"
|
|
235
|
+
* await getLanguageName("zh", "es"); // "chino"
|
|
236
|
+
*
|
|
237
|
+
* // Chinese
|
|
238
|
+
* await getLanguageName("en", "zh"); // "英语"
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
declare function getLanguageName(languageCode: string, displayLanguage?: string): Promise<string>;
|
|
242
|
+
/**
|
|
243
|
+
* Gets a script name in the specified display language
|
|
244
|
+
*
|
|
245
|
+
* @param scriptCode - The ISO script code (e.g., "Hans", "Hant", "Latn")
|
|
246
|
+
* @param displayLanguage - The language to display the name in (default: "en")
|
|
247
|
+
* @returns Promise<string> - The localized script name
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* // Default English
|
|
252
|
+
* await getScriptName("Hans"); // "Simplified"
|
|
253
|
+
* await getScriptName("Hant"); // "Traditional"
|
|
254
|
+
* await getScriptName("Latn"); // "Latin"
|
|
255
|
+
*
|
|
256
|
+
* // Spanish
|
|
257
|
+
* await getScriptName("Hans", "es"); // "simplificado"
|
|
258
|
+
* await getScriptName("Cyrl", "es"); // "cirílico"
|
|
259
|
+
*
|
|
260
|
+
* // Chinese
|
|
261
|
+
* await getScriptName("Latn", "zh"); // "拉丁文"
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
declare function getScriptName(scriptCode: string, displayLanguage?: string): Promise<string>;
|
|
265
|
+
|
|
266
|
+
export { LOCALE_REGEX, type LocaleComponents, type LocaleDelimiter, type ParseResult, getCountryName, getLanguageCode, getLanguageName, getRegionCode, getScriptCode, getScriptName, isValidLanguageCode, isValidLocale, isValidRegionCode, isValidScriptCode, parseLocale, parseLocaleWithDetails };
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the components of a locale string
|
|
3
|
+
*/
|
|
4
|
+
interface LocaleComponents {
|
|
5
|
+
/** The language code (e.g., "en", "zh", "es") */
|
|
6
|
+
language: string;
|
|
7
|
+
/** The script code (e.g., "Hans", "Hant", "Cyrl") - optional */
|
|
8
|
+
script?: string;
|
|
9
|
+
/** The region/country code (e.g., "US", "CN", "RS") - optional */
|
|
10
|
+
region?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Locale delimiter types
|
|
14
|
+
*/
|
|
15
|
+
type LocaleDelimiter = "-" | "_";
|
|
16
|
+
/**
|
|
17
|
+
* Validation result for locale parsing
|
|
18
|
+
*/
|
|
19
|
+
interface ParseResult {
|
|
20
|
+
/** The parsed locale components */
|
|
21
|
+
components: LocaleComponents;
|
|
22
|
+
/** The delimiter used in the original string */
|
|
23
|
+
delimiter: LocaleDelimiter | null;
|
|
24
|
+
/** Whether the locale string was valid */
|
|
25
|
+
isValid: boolean;
|
|
26
|
+
/** Error message if parsing failed */
|
|
27
|
+
error?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Shared constants for locale parsing and validation
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Regular expression for parsing locale strings
|
|
35
|
+
*
|
|
36
|
+
* This regex is case-sensitive and expects normalized locale strings:
|
|
37
|
+
* - Language code: 2-3 lowercase letters (e.g., "en", "zh", "es")
|
|
38
|
+
* - Script code: 4 letters with preserved case (e.g., "Hans", "hans", "Cyrl")
|
|
39
|
+
* - Region code: 2-3 uppercase letters or digits (e.g., "US", "CN", "123")
|
|
40
|
+
*
|
|
41
|
+
* Matches locale strings in the format: language[-_]script?[-_]region?
|
|
42
|
+
*
|
|
43
|
+
* Groups:
|
|
44
|
+
* 1. Language code (2-3 lowercase letters)
|
|
45
|
+
* 2. Script code (4 letters, optional)
|
|
46
|
+
* 3. Region code (2-3 letters or digits, optional)
|
|
47
|
+
*
|
|
48
|
+
* Examples:
|
|
49
|
+
* - "en" -> language: "en"
|
|
50
|
+
* - "en-US" -> language: "en", region: "US"
|
|
51
|
+
* - "zh-Hans-CN" -> language: "zh", script: "Hans", region: "CN"
|
|
52
|
+
* - "sr_Cyrl_RS" -> language: "sr", script: "Cyrl", region: "RS"
|
|
53
|
+
*
|
|
54
|
+
* Note: The parser automatically normalizes case before applying this regex:
|
|
55
|
+
* - Language codes are converted to lowercase
|
|
56
|
+
* - Script codes preserve their original case
|
|
57
|
+
* - Region codes are converted to uppercase
|
|
58
|
+
*/
|
|
59
|
+
declare const LOCALE_REGEX: RegExp;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Breaks apart a locale string into its components
|
|
63
|
+
*
|
|
64
|
+
* @param locale - The locale string to parse
|
|
65
|
+
* @returns LocaleComponents object with language, script, and region
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* parseLocale("en-US"); // { language: "en", region: "US" }
|
|
70
|
+
* parseLocale("en_US"); // { language: "en", region: "US" }
|
|
71
|
+
* parseLocale("zh-Hans-CN"); // { language: "zh", script: "Hans", region: "CN" }
|
|
72
|
+
* parseLocale("zh_Hans_CN"); // { language: "zh", script: "Hans", region: "CN" }
|
|
73
|
+
* parseLocale("es"); // { language: "es" }
|
|
74
|
+
* parseLocale("sr-Cyrl-RS"); // { language: "sr", script: "Cyrl", region: "RS" }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function parseLocale(locale: string): LocaleComponents;
|
|
78
|
+
/**
|
|
79
|
+
* Parses a locale string and returns detailed information about the parsing result
|
|
80
|
+
*
|
|
81
|
+
* @param locale - The locale string to parse
|
|
82
|
+
* @returns ParseResult with components, delimiter, and validation info
|
|
83
|
+
*/
|
|
84
|
+
declare function parseLocaleWithDetails(locale: string): ParseResult;
|
|
85
|
+
/**
|
|
86
|
+
* Extracts just the language code from a locale string
|
|
87
|
+
*
|
|
88
|
+
* @param locale - The locale string to parse
|
|
89
|
+
* @returns The language code
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* getLanguageCode("en-US"); // "en"
|
|
94
|
+
* getLanguageCode("zh-Hans-CN"); // "zh"
|
|
95
|
+
* getLanguageCode("es-MX"); // "es"
|
|
96
|
+
* getLanguageCode("fr_CA"); // "fr"
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function getLanguageCode(locale: string): string;
|
|
100
|
+
/**
|
|
101
|
+
* Extracts the script code from a locale string
|
|
102
|
+
*
|
|
103
|
+
* @param locale - The locale string to parse
|
|
104
|
+
* @returns The script code or null if not present
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* getScriptCode("zh-Hans-CN"); // "Hans"
|
|
109
|
+
* getScriptCode("zh-Hant-TW"); // "Hant"
|
|
110
|
+
* getScriptCode("sr-Cyrl-RS"); // "Cyrl"
|
|
111
|
+
* getScriptCode("en-US"); // null
|
|
112
|
+
* getScriptCode("es"); // null
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
declare function getScriptCode(locale: string): string | null;
|
|
116
|
+
/**
|
|
117
|
+
* Extracts the region/country code from a locale string
|
|
118
|
+
*
|
|
119
|
+
* @param locale - The locale string to parse
|
|
120
|
+
* @returns The region code or null if not present
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* getRegionCode("en-US"); // "US"
|
|
125
|
+
* getRegionCode("zh-Hans-CN"); // "CN"
|
|
126
|
+
* getRegionCode("es"); // null
|
|
127
|
+
* getRegionCode("fr_CA"); // "CA"
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
declare function getRegionCode(locale: string): string | null;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Checks if a locale string is properly formatted and uses real codes
|
|
134
|
+
*
|
|
135
|
+
* @param locale - The locale string to validate
|
|
136
|
+
* @returns true if the locale is valid, false otherwise
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* isValidLocale("en-US"); // true
|
|
141
|
+
* isValidLocale("en_US"); // true
|
|
142
|
+
* isValidLocale("zh-Hans-CN"); // true
|
|
143
|
+
* isValidLocale("invalid"); // false
|
|
144
|
+
* isValidLocale("en-FAKE"); // false
|
|
145
|
+
* isValidLocale("xyz-US"); // false
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
declare function isValidLocale(locale: string): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Checks if a language code is valid
|
|
151
|
+
*
|
|
152
|
+
* @param code - The language code to validate
|
|
153
|
+
* @returns true if the language code is valid, false otherwise
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* isValidLanguageCode("en"); // true
|
|
158
|
+
* isValidLanguageCode("zh"); // true
|
|
159
|
+
* isValidLanguageCode("es"); // true
|
|
160
|
+
* isValidLanguageCode("xyz"); // false
|
|
161
|
+
* isValidLanguageCode("fake"); // false
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function isValidLanguageCode(code: string): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Checks if a script code is valid
|
|
167
|
+
*
|
|
168
|
+
* @param code - The script code to validate
|
|
169
|
+
* @returns true if the script code is valid, false otherwise
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* isValidScriptCode("Hans"); // true (Simplified Chinese)
|
|
174
|
+
* isValidScriptCode("Hant"); // true (Traditional Chinese)
|
|
175
|
+
* isValidScriptCode("Latn"); // true (Latin alphabet)
|
|
176
|
+
* isValidScriptCode("Cyrl"); // true (Cyrillic)
|
|
177
|
+
* isValidScriptCode("Fake"); // false
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
declare function isValidScriptCode(code: string): boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Checks if a region/country code is valid
|
|
183
|
+
*
|
|
184
|
+
* @param code - The region code to validate
|
|
185
|
+
* @returns true if the region code is valid, false otherwise
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* isValidRegionCode("US"); // true
|
|
190
|
+
* isValidRegionCode("CN"); // true
|
|
191
|
+
* isValidRegionCode("GB"); // true
|
|
192
|
+
* isValidRegionCode("ZZ"); // false
|
|
193
|
+
* isValidRegionCode("FAKE"); // false
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
declare function isValidRegionCode(code: string): boolean;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Gets a country name in the specified display language
|
|
200
|
+
*
|
|
201
|
+
* @param countryCode - The ISO country code (e.g., "US", "CN", "DE")
|
|
202
|
+
* @param displayLanguage - The language to display the name in (default: "en")
|
|
203
|
+
* @returns Promise<string> - The localized country name
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* // Default English
|
|
208
|
+
* await getCountryName("US"); // "United States"
|
|
209
|
+
* await getCountryName("CN"); // "China"
|
|
210
|
+
*
|
|
211
|
+
* // Spanish
|
|
212
|
+
* await getCountryName("US", "es"); // "Estados Unidos"
|
|
213
|
+
* await getCountryName("CN", "es"); // "China"
|
|
214
|
+
*
|
|
215
|
+
* // French
|
|
216
|
+
* await getCountryName("US", "fr"); // "États-Unis"
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
declare function getCountryName(countryCode: string, displayLanguage?: string): Promise<string>;
|
|
220
|
+
/**
|
|
221
|
+
* Gets a language name in the specified display language
|
|
222
|
+
*
|
|
223
|
+
* @param languageCode - The ISO language code (e.g., "en", "zh", "es")
|
|
224
|
+
* @param displayLanguage - The language to display the name in (default: "en")
|
|
225
|
+
* @returns Promise<string> - The localized language name
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```typescript
|
|
229
|
+
* // Default English
|
|
230
|
+
* await getLanguageName("en"); // "English"
|
|
231
|
+
* await getLanguageName("zh"); // "Chinese"
|
|
232
|
+
*
|
|
233
|
+
* // Spanish
|
|
234
|
+
* await getLanguageName("en", "es"); // "inglés"
|
|
235
|
+
* await getLanguageName("zh", "es"); // "chino"
|
|
236
|
+
*
|
|
237
|
+
* // Chinese
|
|
238
|
+
* await getLanguageName("en", "zh"); // "英语"
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
declare function getLanguageName(languageCode: string, displayLanguage?: string): Promise<string>;
|
|
242
|
+
/**
|
|
243
|
+
* Gets a script name in the specified display language
|
|
244
|
+
*
|
|
245
|
+
* @param scriptCode - The ISO script code (e.g., "Hans", "Hant", "Latn")
|
|
246
|
+
* @param displayLanguage - The language to display the name in (default: "en")
|
|
247
|
+
* @returns Promise<string> - The localized script name
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* // Default English
|
|
252
|
+
* await getScriptName("Hans"); // "Simplified"
|
|
253
|
+
* await getScriptName("Hant"); // "Traditional"
|
|
254
|
+
* await getScriptName("Latn"); // "Latin"
|
|
255
|
+
*
|
|
256
|
+
* // Spanish
|
|
257
|
+
* await getScriptName("Hans", "es"); // "simplificado"
|
|
258
|
+
* await getScriptName("Cyrl", "es"); // "cirílico"
|
|
259
|
+
*
|
|
260
|
+
* // Chinese
|
|
261
|
+
* await getScriptName("Latn", "zh"); // "拉丁文"
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
declare function getScriptName(scriptCode: string, displayLanguage?: string): Promise<string>;
|
|
265
|
+
|
|
266
|
+
export { LOCALE_REGEX, type LocaleComponents, type LocaleDelimiter, type ParseResult, getCountryName, getLanguageCode, getLanguageName, getRegionCode, getScriptCode, getScriptName, isValidLanguageCode, isValidLocale, isValidRegionCode, isValidScriptCode, parseLocale, parseLocaleWithDetails };
|