11import Z from 'zod' ;
22
3+ // Core locales
4+ const coreFullLocales = [
5+ 'en-US' , // English (United States)
6+ 'es-ES' , // Spanish (Spain)
7+ 'fr-FR' , // French (France)
8+ 'ca-ES' , // Catalan (Spain)
9+ 'ja-JP' , // Japanese (Japan)
10+ 'de-DE' , // German (Germany)
11+ 'pt-PT' , // Portuguese (Portugal)
12+ 'it-IT' , // Italian (Italy)
13+ 'ru-RU' , // Russian (Russia)
14+ 'uk-UA' , // Ukrainian (Ukraine)
15+ 'hi-IN' , // Hindi (India)
16+ 'zh-Hans-CN' , // Simplified Chinese (China)
17+ 'ko-KR' , // Korean (South Korea)
18+ 'tr-TR' , // Turkish (Turkey)
19+ 'ar-EG' , // Arabic (Egypt)
20+ ] as const ;
21+ const coreShortcutLocales = [
22+ 'en' , // English
23+ 'es' , // Spanish
24+ 'fr' , // French
25+ 'ca' , // Catalan
26+ 'ja' , // Japanese
27+ 'de' , // German
28+ 'pt' , // Portuguese
29+ 'it' , // Italian
30+ 'ru' , // Russian
31+ 'uk' , // Ukrainian
32+ 'hi' , // Hindi
33+ 'zh' , // Simplified Chinese
34+ 'zh-Hans' , // Simplified Chinese
35+ 'ko' , // Korean
36+ 'tr' , // Turkish
37+ 'ar' , // Arabic
38+ ] as const ;
339const coreLocales = [
4- 'en' , // English
5- 'es' , // Spanish
6- 'fr' , // French
7- 'ca' , // Catalan
8- 'ja' , // Japanese
9- 'de' , // German
10- 'pt' , // Portuguese
11- 'it' , // Italian
12- 'ru' , // Russian
13- 'uk' , // Ukrainian
14- 'hi' , // Hindi
15- 'zh' , // Mandarin
16- 'ko' , // Korean
17- 'tr' , // Turkish
18- 'ar' , // Arabic
19-
20- ] as const ;
21-
22- // Source
23- export const sourceLocales = [
24- ...coreLocales ,
25- 'cs' , // Czech
26- 'yue' , // Cantonese
27- 'pl' , // Polish
28- 'sk' , // Slovak
29- 'th' , // Thai
40+ ...coreFullLocales ,
41+ ...coreShortcutLocales ,
3042] as const ;
3143
32- export const sourceLocaleSchema = Z . enum ( sourceLocales ) ;
44+ // Source locales
45+ const sourceOnlyFullLocales = [
46+ 'cs-CZ' , // Czech (Czech Republic)
47+ 'zh-Hant-HK' , // Traditional Chinese (Hong Kong)
48+ 'pl-PL' , // Polish (Poland)
49+ 'sk-SK' , // Slovak (Slovakia)
50+ 'th-TH' , // Thai (Thailand)
51+ ] as const ;
52+ const sourceOnlyShortcutLocales = [
53+ 'pl' , // Polish
54+ 'cs' , // Czech
55+ 'zh-Hant' , // Traditional Chinese
56+ 'pl' , // Polish
57+ 'sk' , // Slovak
58+ 'th' , // Thai
59+ ] as const ;
60+ const sourceOnlyLocales = [
61+ ...sourceOnlyFullLocales ,
62+ ...sourceOnlyShortcutLocales ,
63+ ] as const ;
64+
65+ const sourceFullLocales = [
66+ ...coreFullLocales ,
67+ ...sourceOnlyFullLocales ,
68+ ] as const ;
69+
70+ const sourceShortcutLocales = [
71+ ...coreShortcutLocales ,
72+ ...sourceOnlyShortcutLocales ,
73+ ] as const ;
74+
75+ const sourceLocales = [
76+ ...coreLocales ,
77+ ...sourceOnlyLocales ,
78+ ] as const ;
79+
80+
81+
82+ // Target locales
83+ const targetOnlyFullLocales = [
84+ 'shyriiwook' , // Shyriiwook
85+ ] as const ;
86+ const targetOnlyShortcutLocales = [
87+ ] as const ;
88+ const targetOnlyLocales = [
89+ ...targetOnlyFullLocales ,
90+ ...targetOnlyShortcutLocales ,
91+ ] as const ;
92+
93+ const targetFullLocales = [
94+ ...coreFullLocales ,
95+ ...targetOnlyFullLocales ,
96+ ] as const ;
97+
98+
99+ const targetShortcutLocales = [
100+ ...coreShortcutLocales ,
101+ ...targetOnlyShortcutLocales ,
102+ ] as const ;
103+ const targetLocales = [
104+ ...coreLocales ,
105+ ...targetOnlyLocales ,
106+ ] as const ;
107+
108+
109+ // Locale resolution map
110+
111+ const coreLocaleResolutionMap : Record < typeof coreShortcutLocales [ number ] , typeof coreFullLocales [ number ] > = {
112+ en : 'en-US' ,
113+ es : 'es-ES' ,
114+ fr : 'fr-FR' ,
115+ ca : 'ca-ES' ,
116+ ja : 'ja-JP' ,
117+ de : 'de-DE' ,
118+ pt : 'pt-PT' ,
119+ it : 'it-IT' ,
120+ ru : 'ru-RU' ,
121+ uk : 'uk-UA' ,
122+ hi : 'hi-IN' ,
123+ zh : 'zh-Hans-CN' ,
124+ 'zh-Hans' : 'zh-Hans-CN' ,
125+ ko : 'ko-KR' ,
126+ tr : 'tr-TR' ,
127+ ar : 'ar-EG' ,
128+ } ;
129+
130+ const sourceOnlyLocaleResolutionMap : Record < typeof sourceOnlyShortcutLocales [ number ] , typeof sourceOnlyFullLocales [ number ] > = {
131+ pl : 'pl-PL' ,
132+ cs : 'cs-CZ' ,
133+ 'zh-Hant' : 'zh-Hant-HK' ,
134+ sk : 'sk-SK' ,
135+ th : 'th-TH' ,
136+ } ;
137+
138+ const targetOnlyLocaleResolutionMap : Record < typeof targetOnlyShortcutLocales [ number ] , typeof targetOnlyFullLocales [ number ] > = {
139+ } ;
140+
141+ const sourceLocaleResolutionMap : Record < typeof sourceShortcutLocales [ number ] , typeof sourceFullLocales [ number ] > = {
142+ ...coreLocaleResolutionMap ,
143+ ...sourceOnlyLocaleResolutionMap ,
144+ } ;
145+
146+ const targetLocaleResolutionMap : Record < typeof targetShortcutLocales [ number ] , typeof targetFullLocales [ number ] > = {
147+ ...coreLocaleResolutionMap ,
148+ ...targetOnlyLocaleResolutionMap ,
149+ } ;
150+
151+ const localeResolutionMap : Record < typeof shortcutLocales [ number ] , typeof fullLocales [ number ] > = {
152+ ...sourceLocaleResolutionMap ,
153+ ...targetLocaleResolutionMap ,
154+ } ;
155+
156+ // Exports
33157
34- // Target
35- export const targetLocales = [
36- ...coreLocales ,
37- 'shyriiwook' , // Wookiee language (Star Wars)
158+ // All locales
159+
160+ export const shortcutLocales = [
161+ ...coreShortcutLocales ,
162+ ...sourceOnlyShortcutLocales ,
163+ ...targetOnlyShortcutLocales ,
164+ ] as const ;
165+
166+ export const fullLocales = [
167+ ...coreFullLocales ,
168+ ...sourceOnlyFullLocales ,
169+ ...targetOnlyFullLocales ,
38170] as const ;
39171
172+ export const allLocales = [
173+ ...coreLocales ,
174+ ...sourceOnlyLocales ,
175+ ...targetOnlyLocales ,
176+ ] as const ;
177+
178+ // Schemas
179+
180+ export const sourceFullLocaleSchema = Z . enum ( sourceFullLocales ) ;
181+ export const sourceLocaleSchema = Z . enum ( sourceLocales ) ;
182+ export const targetFullLocaleSchema = Z . enum ( targetFullLocales ) ;
40183export const targetLocaleSchema = Z . enum ( targetLocales ) ;
184+
185+ // Shortcut resolvers
186+
187+ export const resolveSourceLocale = ( locale : typeof sourceLocales [ number ] ) : typeof sourceFullLocales [ number ] => {
188+ if ( sourceFullLocales . includes ( locale as typeof sourceFullLocales [ number ] ) ) {
189+ return locale as typeof sourceFullLocales [ number ] ;
190+ }
191+ return sourceLocaleResolutionMap [ locale as typeof sourceShortcutLocales [ number ] ] ;
192+ } ;
193+
194+ export const resolveTargetLocale = ( locale : typeof targetLocales [ number ] ) : typeof targetFullLocales [ number ] => {
195+ if ( targetFullLocales . includes ( locale as typeof targetFullLocales [ number ] ) ) {
196+ return locale as typeof targetFullLocales [ number ] ;
197+ }
198+ return targetLocaleResolutionMap [ locale as typeof targetShortcutLocales [ number ] ] ;
199+ } ;
200+
201+ export const resolveLocale = ( locale : typeof allLocales [ number ] ) : typeof fullLocales [ number ] => {
202+ if ( fullLocales . includes ( locale as typeof fullLocales [ number ] ) ) {
203+ return locale as typeof fullLocales [ number ] ;
204+ }
205+ return localeResolutionMap [ locale as typeof shortcutLocales [ number ] ] ;
206+ }
0 commit comments