-
-
Notifications
You must be signed in to change notification settings - Fork 815
Expand file tree
/
Copy pathlocale.go
More file actions
288 lines (259 loc) · 7.43 KB
/
Copy pathlocale.go
File metadata and controls
288 lines (259 loc) · 7.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
package enum
import (
"github.com/pemistahl/lingua-go"
)
// This file is the single source of truth for all locale/language definitions in Fider.
// When adding a new language, update this file first, then follow the complete guide at:
// /locale/README.md
// Locale represents a supported language/locale in Fider
type Locale struct {
Code string // Locale code (e.g., "pt-BR", "en")
Name string // Display name (e.g., "Portuguese (Brazilian)")
MessageFormatCode string // Culture code for messageformat pluralization (e.g., "pt")
PostgresConfig string // PostgreSQL text search configuration (e.g., "portuguese", "simple")
LinguaLanguage lingua.Language // Lingua-go language enum for detection
IsRTL bool // Right-to-left text direction
}
var (
// LocaleEnglish represents English
LocaleEnglish = Locale{
Code: "en",
Name: "English",
MessageFormatCode: "en",
PostgresConfig: "english",
LinguaLanguage: lingua.English,
IsRTL: false,
}
// LocalePortugueseBR represents Portuguese (Brazilian)
LocalePortugueseBR = Locale{
Code: "pt-BR",
Name: "Portuguese (Brazilian)",
MessageFormatCode: "pt",
PostgresConfig: "portuguese",
LinguaLanguage: lingua.Portuguese,
IsRTL: false,
}
// LocalePortuguesePT represents Portuguese (Portugal)
LocalePortuguesePT = Locale{
Code: "pt-PT",
Name: "Portuguese (Portugal)",
MessageFormatCode: "pt",
PostgresConfig: "portuguese",
LinguaLanguage: lingua.Portuguese,
IsRTL: false,
}
// LocaleSpanishES represents Spanish
LocaleSpanishES = Locale{
Code: "es-ES",
Name: "Spanish",
MessageFormatCode: "es",
PostgresConfig: "spanish",
LinguaLanguage: lingua.Spanish,
IsRTL: false,
}
// LocaleGerman represents German
LocaleGerman = Locale{
Code: "de",
Name: "German",
MessageFormatCode: "de",
PostgresConfig: "german",
LinguaLanguage: lingua.German,
IsRTL: false,
}
// LocaleFrench represents French
LocaleFrench = Locale{
Code: "fr",
Name: "French",
MessageFormatCode: "fr",
PostgresConfig: "french",
LinguaLanguage: lingua.French,
IsRTL: false,
}
// LocaleSwedishSE represents Swedish
LocaleSwedishSE = Locale{
Code: "sv-SE",
Name: "Swedish",
MessageFormatCode: "se",
PostgresConfig: "swedish",
LinguaLanguage: lingua.Swedish,
IsRTL: false,
}
// LocaleItalian represents Italian
LocaleItalian = Locale{
Code: "it",
Name: "Italian",
MessageFormatCode: "it",
PostgresConfig: "italian",
LinguaLanguage: lingua.Italian,
IsRTL: false,
}
// LocaleJapanese represents Japanese
LocaleJapanese = Locale{
Code: "ja",
Name: "Japanese",
MessageFormatCode: "ja",
PostgresConfig: "simple",
LinguaLanguage: lingua.Japanese,
IsRTL: false,
}
// LocaleDutch represents Dutch
LocaleDutch = Locale{
Code: "nl",
Name: "Dutch",
MessageFormatCode: "nl",
PostgresConfig: "dutch",
LinguaLanguage: lingua.Dutch,
IsRTL: false,
}
// LocalePolish represents Polish
LocalePolish = Locale{
Code: "pl",
Name: "Polish",
MessageFormatCode: "pl",
PostgresConfig: "simple",
LinguaLanguage: lingua.Polish,
IsRTL: false,
}
// LocaleRussian represents Russian
LocaleRussian = Locale{
Code: "ru",
Name: "Russian",
MessageFormatCode: "ru",
PostgresConfig: "russian",
LinguaLanguage: lingua.Russian,
IsRTL: false,
}
// LocaleSlovak represents Slovak
LocaleSlovak = Locale{
Code: "sk",
Name: "Slovak",
MessageFormatCode: "sk",
PostgresConfig: "simple",
LinguaLanguage: lingua.Slovak,
IsRTL: false,
}
// LocaleTurkish represents Turkish
LocaleTurkish = Locale{
Code: "tr",
Name: "Turkish",
MessageFormatCode: "tr",
PostgresConfig: "turkish",
LinguaLanguage: lingua.Turkish,
IsRTL: false,
}
// LocaleGreek represents Greek
LocaleGreek = Locale{
Code: "el",
Name: "Greek",
MessageFormatCode: "el",
PostgresConfig: "simple",
LinguaLanguage: lingua.Greek,
IsRTL: false,
}
// LocaleArabic represents Arabic
LocaleArabic = Locale{
Code: "ar",
Name: "Arabic",
MessageFormatCode: "ar",
PostgresConfig: "arabic",
LinguaLanguage: lingua.Arabic,
IsRTL: true,
}
// LocaleChineseCN represents Chinese (Simplified)
LocaleChineseCN = Locale{
Code: "zh-CN",
Name: "Chinese (Simplified)",
MessageFormatCode: "zh",
PostgresConfig: "simple",
LinguaLanguage: lingua.Chinese,
IsRTL: false,
}
// LocaleChineseTW represents Chinese (Traditional)
LocaleChineseTW = Locale{
Code: "zh-TW",
Name: "Chinese (Traditional)",
MessageFormatCode: "zh",
PostgresConfig: "simple",
LinguaLanguage: lingua.Chinese,
IsRTL: false,
}
// LocalePersian represents Persian (Farsi)
LocalePersian = Locale{
Code: "fa",
Name: "Persian (پارسی)",
MessageFormatCode: "fa",
PostgresConfig: "simple",
LinguaLanguage: lingua.Persian,
IsRTL: false,
}
// AllLocales contains all supported locales
AllLocales = []Locale{
LocaleEnglish,
LocalePortugueseBR,
LocalePortuguesePT,
LocaleSpanishES,
LocaleGerman,
LocaleFrench,
LocaleSwedishSE,
LocaleItalian,
LocaleJapanese,
LocaleDutch,
LocalePolish,
LocaleRussian,
LocaleSlovak,
LocaleTurkish,
LocaleGreek,
LocaleArabic,
LocaleChineseCN,
LocaleChineseTW,
LocalePersian,
}
)
// GetLocaleByCode returns a Locale by its code, or false if not found
func GetLocaleByCode(code string) (Locale, bool) {
for _, locale := range AllLocales {
if locale.Code == code {
return locale, true
}
}
return Locale{}, false
}
// IsValidLocale returns true if the given locale code is valid
func IsValidLocale(code string) bool {
_, valid := GetLocaleByCode(code)
return valid
}
// GetLinguaLanguages returns all lingua.Language enums for language detection
func GetLinguaLanguages() []lingua.Language {
languages := make([]lingua.Language, len(AllLocales))
for i, locale := range AllLocales {
languages[i] = locale.LinguaLanguage
}
return languages
}
// GetLocaleByLinguaLanguage returns a Locale by its lingua.Language enum
func GetLocaleByLinguaLanguage(lang lingua.Language) (Locale, bool) {
for _, locale := range AllLocales {
if locale.LinguaLanguage == lang {
return locale, true
}
}
return Locale{}, false
}
// MapLocaleToTSConfig maps a locale code to a PostgreSQL text search configuration
// Returns "simple" if the locale is not found or doesn't have native Postgres support
func MapLocaleToTSConfig(code string) string {
locale, found := GetLocaleByCode(code)
if !found {
return "simple"
}
return locale.PostgresConfig
}
// GetLocaleCodes returns all locale codes
func GetLocaleCodes() []string {
codes := make([]string, len(AllLocales))
for i, locale := range AllLocales {
codes[i] = locale.Code
}
return codes
}