@quenty/time 2.5.0 → 2.6.1

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.
@@ -0,0 +1,964 @@
1
+ --!strict
2
+ --[=[
3
+ Locale strings for [TimeCalendarUtils], [RelativeTimeUtils] and [TimeDurationUtils], covering
4
+ the same locales as [NumberLocalizationUtils]. Lookups resolve through [ResolveLocaleUtils],
5
+ so `en-gb` lands on English and `es-mx` on Spanish, and an unknown locale falls back to English
6
+ with a warning.
7
+
8
+ To add a locale, add one entry to `LOCALES`. Every field is required, so a missing phrase is a
9
+ type error rather than a runtime surprise.
10
+
11
+ @class TimeLocalizationUtils
12
+ ]=]
13
+
14
+ local require = require(script.Parent.loader).load(script)
15
+
16
+ local ResolveLocaleUtils = require("ResolveLocaleUtils")
17
+
18
+ local TimeLocalizationUtils = {}
19
+
20
+ local DEFAULT_LOCALE = "en-us"
21
+
22
+ --[=[
23
+ A [Time.format] template, or a function given the time and the reference time that returns
24
+ the finished text.
25
+
26
+ @type CalendarFormat string | (dateTime: DateTime, referenceTime: DateTime) -> string
27
+ @within TimeLocalizationUtils
28
+ ]=]
29
+ export type CalendarFormat = string | (DateTime, DateTime) -> string
30
+
31
+ --[=[
32
+ The phrase [TimeCalendarUtils.calendar] uses for each distance from the reference day.
33
+
34
+ @interface CalendarFormats
35
+ .sameDay CalendarFormat
36
+ .nextDay CalendarFormat
37
+ .nextWeek CalendarFormat
38
+ .lastDay CalendarFormat
39
+ .lastWeek CalendarFormat
40
+ .sameElse CalendarFormat
41
+ @within TimeLocalizationUtils
42
+ ]=]
43
+ export type CalendarFormats = {
44
+ sameDay: CalendarFormat,
45
+ nextDay: CalendarFormat,
46
+ nextWeek: CalendarFormat,
47
+ lastDay: CalendarFormat,
48
+ lastWeek: CalendarFormat,
49
+ sameElse: CalendarFormat,
50
+ }
51
+
52
+ --[=[
53
+ A partial [CalendarFormats] a caller passes to override a locale's phrases.
54
+
55
+ @type CalendarFormatOverrides { sameDay: CalendarFormat?, nextDay: CalendarFormat?, nextWeek: CalendarFormat?, lastDay: CalendarFormat?, lastWeek: CalendarFormat?, sameElse: CalendarFormat? }
56
+ @within TimeLocalizationUtils
57
+ ]=]
58
+ export type CalendarFormatOverrides = {
59
+ sameDay: CalendarFormat?,
60
+ nextDay: CalendarFormat?,
61
+ nextWeek: CalendarFormat?,
62
+ lastDay: CalendarFormat?,
63
+ lastWeek: CalendarFormat?,
64
+ sameElse: CalendarFormat?,
65
+ }
66
+
67
+ --[=[
68
+ A relative time string with `%d` for the amount, or a function given the
69
+ amount, whether a suffix will be added, the threshold key and whether the time is in the
70
+ future, for languages that inflect.
71
+
72
+ @type RelativeTimeString string | (amount: number, withoutSuffix: boolean, key: string, isFuture: boolean) -> string
73
+ @within TimeLocalizationUtils
74
+ ]=]
75
+ export type RelativeTimeString = string | (number, boolean, string, boolean) -> string
76
+
77
+ --[=[
78
+ Relative time strings for every threshold key. `future` and `past` take `%s`.
79
+
80
+ @interface RelativeTimeStrings
81
+ .future string
82
+ .past string
83
+ .s RelativeTimeString
84
+ .m RelativeTimeString
85
+ .mm RelativeTimeString
86
+ .h RelativeTimeString
87
+ .hh RelativeTimeString
88
+ .d RelativeTimeString
89
+ .dd RelativeTimeString
90
+ .M RelativeTimeString
91
+ .MM RelativeTimeString
92
+ .y RelativeTimeString
93
+ .yy RelativeTimeString
94
+ @within TimeLocalizationUtils
95
+ ]=]
96
+ export type RelativeTimeStrings = {
97
+ future: string,
98
+ past: string,
99
+ s: RelativeTimeString,
100
+ m: RelativeTimeString,
101
+ mm: RelativeTimeString,
102
+ h: RelativeTimeString,
103
+ hh: RelativeTimeString,
104
+ d: RelativeTimeString,
105
+ dd: RelativeTimeString,
106
+ M: RelativeTimeString,
107
+ MM: RelativeTimeString,
108
+ y: RelativeTimeString,
109
+ yy: RelativeTimeString,
110
+ }
111
+
112
+ --[=[
113
+ Relative time strings a caller passes to override or extend a locale's, keyed by threshold
114
+ key. Custom thresholds may add their own keys here.
115
+
116
+ @type RelativeTimeStringOverrides { [string]: RelativeTimeString }
117
+ @within TimeLocalizationUtils
118
+ ]=]
119
+ export type RelativeTimeStringOverrides = { [string]: RelativeTimeString }
120
+
121
+ --[=[
122
+ A duration phrase with `%d` for the amount: a singular and plural pair, or a function of the
123
+ amount for languages with more plural forms.
124
+
125
+ @type DurationPhrase { one: string, other: string } | (amount: number) -> string
126
+ @within TimeLocalizationUtils
127
+ ]=]
128
+ export type DurationPhrase = { one: string, other: string } | (number) -> string
129
+
130
+ --[=[
131
+ Duration phrases for every breakdown field.
132
+
133
+ @interface DurationStrings
134
+ .years DurationPhrase
135
+ .months DurationPhrase
136
+ .weeks DurationPhrase
137
+ .days DurationPhrase
138
+ .hours DurationPhrase
139
+ .minutes DurationPhrase
140
+ .seconds DurationPhrase
141
+ .milliseconds DurationPhrase
142
+ @within TimeLocalizationUtils
143
+ ]=]
144
+ export type DurationStrings = {
145
+ years: DurationPhrase,
146
+ months: DurationPhrase,
147
+ weeks: DurationPhrase,
148
+ days: DurationPhrase,
149
+ hours: DurationPhrase,
150
+ minutes: DurationPhrase,
151
+ seconds: DurationPhrase,
152
+ milliseconds: DurationPhrase,
153
+ }
154
+
155
+ --[=[
156
+ Duration phrases a caller passes to override a locale's, keyed by breakdown field.
157
+
158
+ @type DurationStringOverrides { [string]: DurationPhrase }
159
+ @within TimeLocalizationUtils
160
+ ]=]
161
+ export type DurationStringOverrides = { [string]: DurationPhrase }
162
+
163
+ --[=[
164
+ Everything one locale needs.
165
+
166
+ @interface TimeLocale
167
+ .calendar CalendarFormats
168
+ .relativeTime RelativeTimeStrings
169
+ .duration DurationStrings
170
+ @within TimeLocalizationUtils
171
+ ]=]
172
+ export type TimeLocale = {
173
+ calendar: CalendarFormats,
174
+ relativeTime: RelativeTimeStrings,
175
+ duration: DurationStrings,
176
+ }
177
+
178
+ function TimeLocalizationUtils._withAmount(amount: number, template: string): string
179
+ return (string.gsub(template, "%%d", tostring(amount)))
180
+ end
181
+
182
+ -- Languages without grammatical number use the same phrase for every amount
183
+ function TimeLocalizationUtils._invariantPhrase(template: string): DurationPhrase
184
+ return { one = template, other = template }
185
+ end
186
+
187
+ -- Russian style: 1, 21, 31 are singular; 2-4, 22-24 are few; the rest (incl. 11-14) are many
188
+ function TimeLocalizationUtils._russianPlural(amount: number, one: string, few: string, many: string): string
189
+ local tens = amount % 100
190
+ local ones = amount % 10
191
+ if ones == 1 and tens ~= 11 then
192
+ return one
193
+ elseif ones >= 2 and ones <= 4 and (tens < 10 or tens >= 20) then
194
+ return few
195
+ else
196
+ return many
197
+ end
198
+ end
199
+
200
+ -- Polish style: only exactly 1 is singular; 2-4, 22-24 are few; the rest are many
201
+ function TimeLocalizationUtils._polishPlural(amount: number, one: string, few: string, many: string): string
202
+ if amount == 1 then
203
+ return one
204
+ end
205
+
206
+ local tens = amount % 100
207
+ local ones = amount % 10
208
+ if ones >= 2 and ones <= 4 and (tens < 10 or tens >= 20) then
209
+ return few
210
+ else
211
+ return many
212
+ end
213
+ end
214
+
215
+ function TimeLocalizationUtils._russianDuration(one: string, few: string, many: string): DurationPhrase
216
+ return function(amount: number): string
217
+ return amount .. " " .. TimeLocalizationUtils._russianPlural(math.abs(amount), one, few, many)
218
+ end
219
+ end
220
+
221
+ function TimeLocalizationUtils._polishDuration(one: string, few: string, many: string): DurationPhrase
222
+ return function(amount: number): string
223
+ return amount .. " " .. TimeLocalizationUtils._polishPlural(math.abs(amount), one, few, many)
224
+ end
225
+ end
226
+
227
+ -- German: nominative on its own, dative after "in" / "vor"
228
+ local GERMAN_RELATIVE_FORMS: { [string]: { string } } = {
229
+ m = { "eine Minute", "einer Minute" },
230
+ h = { "eine Stunde", "einer Stunde" },
231
+ d = { "ein Tag", "einem Tag" },
232
+ dd = { "%d Tage", "%d Tagen" },
233
+ M = { "ein Monat", "einem Monat" },
234
+ MM = { "%d Monate", "%d Monaten" },
235
+ y = { "ein Jahr", "einem Jahr" },
236
+ yy = { "%d Jahre", "%d Jahren" },
237
+ }
238
+
239
+ function TimeLocalizationUtils._germanRelative(
240
+ amount: number,
241
+ withoutSuffix: boolean,
242
+ key: string,
243
+ _isFuture: boolean
244
+ ): string
245
+ local forms = GERMAN_RELATIVE_FORMS[key]
246
+ return TimeLocalizationUtils._withAmount(amount, if withoutSuffix then forms[1] else forms[2])
247
+ end
248
+
249
+ local RUSSIAN_RELATIVE_FORMS: { [string]: { string } } = {
250
+ mm = { "минута", "минуты", "минут" },
251
+ hh = { "час", "часа", "часов" },
252
+ dd = { "день", "дня", "дней" },
253
+ MM = { "месяц", "месяца", "месяцев" },
254
+ yy = { "год", "года", "лет" },
255
+ }
256
+
257
+ function TimeLocalizationUtils._russianRelative(
258
+ amount: number,
259
+ withoutSuffix: boolean,
260
+ key: string,
261
+ _isFuture: boolean
262
+ ): string
263
+ if key == "m" then
264
+ return if withoutSuffix then "минута" else "минуту"
265
+ end
266
+
267
+ local forms = RUSSIAN_RELATIVE_FORMS[key]
268
+ -- "минуту" is the accusative used after "через" / before "назад"
269
+ local one = if key == "mm" and not withoutSuffix then "минуту" else forms[1]
270
+ return amount .. " " .. TimeLocalizationUtils._russianPlural(amount, one, forms[2], forms[3])
271
+ end
272
+
273
+ function TimeLocalizationUtils._polishRelative(
274
+ amount: number,
275
+ withoutSuffix: boolean,
276
+ key: string,
277
+ _isFuture: boolean
278
+ ): string
279
+ if key == "m" then
280
+ return if withoutSuffix then "minuta" else "minutę"
281
+ elseif key == "h" then
282
+ return if withoutSuffix then "godzina" else "godzinę"
283
+ elseif key == "mm" then
284
+ return amount .. " " .. TimeLocalizationUtils._polishPlural(amount, "minuta", "minuty", "minut")
285
+ elseif key == "hh" then
286
+ return amount .. " " .. TimeLocalizationUtils._polishPlural(amount, "godzina", "godziny", "godzin")
287
+ elseif key == "MM" then
288
+ return amount .. " " .. TimeLocalizationUtils._polishPlural(amount, "miesiąc", "miesiące", "miesięcy")
289
+ elseif key == "yy" then
290
+ return amount .. " " .. TimeLocalizationUtils._polishPlural(amount, "rok", "lata", "lat")
291
+ else
292
+ error(string.format("No Polish relative form for %q", key))
293
+ end
294
+ end
295
+
296
+ local LOCALES: { [string]: TimeLocale } = {
297
+ en = {
298
+ calendar = {
299
+ sameDay = "[Today at] LT",
300
+ nextDay = "[Tomorrow at] LT",
301
+ nextWeek = "dddd [at] LT",
302
+ lastDay = "[Yesterday at] LT",
303
+ lastWeek = "[Last] dddd [at] LT",
304
+ sameElse = "L",
305
+ },
306
+ relativeTime = {
307
+ future = "in %s",
308
+ past = "%s ago",
309
+ s = "a few seconds",
310
+ m = "a minute",
311
+ mm = "%d minutes",
312
+ h = "an hour",
313
+ hh = "%d hours",
314
+ d = "a day",
315
+ dd = "%d days",
316
+ M = "a month",
317
+ MM = "%d months",
318
+ y = "a year",
319
+ yy = "%d years",
320
+ },
321
+ duration = {
322
+ years = { one = "%d year", other = "%d years" },
323
+ months = { one = "%d month", other = "%d months" },
324
+ weeks = { one = "%d week", other = "%d weeks" },
325
+ days = { one = "%d day", other = "%d days" },
326
+ hours = { one = "%d hour", other = "%d hours" },
327
+ minutes = { one = "%d minute", other = "%d minutes" },
328
+ seconds = { one = "%d second", other = "%d seconds" },
329
+ milliseconds = { one = "%d millisecond", other = "%d milliseconds" },
330
+ },
331
+ },
332
+
333
+ es = {
334
+ calendar = {
335
+ sameDay = "[hoy a las] LT",
336
+ nextDay = "[mañana a las] LT",
337
+ nextWeek = "dddd [a las] LT",
338
+ lastDay = "[ayer a las] LT",
339
+ lastWeek = "[el] dddd [pasado a las] LT",
340
+ sameElse = "L",
341
+ },
342
+ relativeTime = {
343
+ future = "en %s",
344
+ past = "hace %s",
345
+ s = "unos segundos",
346
+ m = "un minuto",
347
+ mm = "%d minutos",
348
+ h = "una hora",
349
+ hh = "%d horas",
350
+ d = "un día",
351
+ dd = "%d días",
352
+ M = "un mes",
353
+ MM = "%d meses",
354
+ y = "un año",
355
+ yy = "%d años",
356
+ },
357
+ duration = {
358
+ years = { one = "%d año", other = "%d años" },
359
+ months = { one = "%d mes", other = "%d meses" },
360
+ weeks = { one = "%d semana", other = "%d semanas" },
361
+ days = { one = "%d día", other = "%d días" },
362
+ hours = { one = "%d hora", other = "%d horas" },
363
+ minutes = { one = "%d minuto", other = "%d minutos" },
364
+ seconds = { one = "%d segundo", other = "%d segundos" },
365
+ milliseconds = { one = "%d milisegundo", other = "%d milisegundos" },
366
+ },
367
+ },
368
+
369
+ fr = {
370
+ calendar = {
371
+ sameDay = "[Aujourd’hui à] LT",
372
+ nextDay = "[Demain à] LT",
373
+ nextWeek = "dddd [à] LT",
374
+ lastDay = "[Hier à] LT",
375
+ lastWeek = "dddd [dernier à] LT",
376
+ sameElse = "L",
377
+ },
378
+ relativeTime = {
379
+ future = "dans %s",
380
+ past = "il y a %s",
381
+ s = "quelques secondes",
382
+ m = "une minute",
383
+ mm = "%d minutes",
384
+ h = "une heure",
385
+ hh = "%d heures",
386
+ d = "un jour",
387
+ dd = "%d jours",
388
+ M = "un mois",
389
+ MM = "%d mois",
390
+ y = "un an",
391
+ yy = "%d ans",
392
+ },
393
+ duration = {
394
+ years = { one = "%d an", other = "%d ans" },
395
+ months = { one = "%d mois", other = "%d mois" },
396
+ weeks = { one = "%d semaine", other = "%d semaines" },
397
+ days = { one = "%d jour", other = "%d jours" },
398
+ hours = { one = "%d heure", other = "%d heures" },
399
+ minutes = { one = "%d minute", other = "%d minutes" },
400
+ seconds = { one = "%d seconde", other = "%d secondes" },
401
+ milliseconds = { one = "%d milliseconde", other = "%d millisecondes" },
402
+ },
403
+ },
404
+
405
+ de = {
406
+ calendar = {
407
+ sameDay = "[heute um] LT [Uhr]",
408
+ nextDay = "[morgen um] LT [Uhr]",
409
+ nextWeek = "dddd [um] LT [Uhr]",
410
+ lastDay = "[gestern um] LT [Uhr]",
411
+ lastWeek = "[letzten] dddd [um] LT [Uhr]",
412
+ sameElse = "L",
413
+ },
414
+ relativeTime = {
415
+ future = "in %s",
416
+ past = "vor %s",
417
+ s = "ein paar Sekunden",
418
+ m = TimeLocalizationUtils._germanRelative,
419
+ mm = "%d Minuten",
420
+ h = TimeLocalizationUtils._germanRelative,
421
+ hh = "%d Stunden",
422
+ d = TimeLocalizationUtils._germanRelative,
423
+ dd = TimeLocalizationUtils._germanRelative,
424
+ M = TimeLocalizationUtils._germanRelative,
425
+ MM = TimeLocalizationUtils._germanRelative,
426
+ y = TimeLocalizationUtils._germanRelative,
427
+ yy = TimeLocalizationUtils._germanRelative,
428
+ },
429
+ duration = {
430
+ years = { one = "%d Jahr", other = "%d Jahre" },
431
+ months = { one = "%d Monat", other = "%d Monate" },
432
+ weeks = { one = "%d Woche", other = "%d Wochen" },
433
+ days = { one = "%d Tag", other = "%d Tage" },
434
+ hours = { one = "%d Stunde", other = "%d Stunden" },
435
+ minutes = { one = "%d Minute", other = "%d Minuten" },
436
+ seconds = { one = "%d Sekunde", other = "%d Sekunden" },
437
+ milliseconds = { one = "%d Millisekunde", other = "%d Millisekunden" },
438
+ },
439
+ },
440
+
441
+ pt = {
442
+ calendar = {
443
+ sameDay = "[Hoje às] LT",
444
+ nextDay = "[Amanhã às] LT",
445
+ nextWeek = "dddd [às] LT",
446
+ lastDay = "[Ontem às] LT",
447
+ lastWeek = "dddd [passado às] LT",
448
+ sameElse = "L",
449
+ },
450
+ relativeTime = {
451
+ future = "em %s",
452
+ past = "há %s",
453
+ s = "poucos segundos",
454
+ m = "um minuto",
455
+ mm = "%d minutos",
456
+ h = "uma hora",
457
+ hh = "%d horas",
458
+ d = "um dia",
459
+ dd = "%d dias",
460
+ M = "um mês",
461
+ MM = "%d meses",
462
+ y = "um ano",
463
+ yy = "%d anos",
464
+ },
465
+ duration = {
466
+ years = { one = "%d ano", other = "%d anos" },
467
+ months = { one = "%d mês", other = "%d meses" },
468
+ weeks = { one = "%d semana", other = "%d semanas" },
469
+ days = { one = "%d dia", other = "%d dias" },
470
+ hours = { one = "%d hora", other = "%d horas" },
471
+ minutes = { one = "%d minuto", other = "%d minutos" },
472
+ seconds = { one = "%d segundo", other = "%d segundos" },
473
+ milliseconds = { one = "%d milissegundo", other = "%d milissegundos" },
474
+ },
475
+ },
476
+
477
+ it = {
478
+ calendar = {
479
+ sameDay = "[Oggi alle] LT",
480
+ nextDay = "[Domani alle] LT",
481
+ nextWeek = "dddd [alle] LT",
482
+ lastDay = "[Ieri alle] LT",
483
+ lastWeek = "[lo scorso] dddd [alle] LT",
484
+ sameElse = "L",
485
+ },
486
+ relativeTime = {
487
+ future = "tra %s",
488
+ past = "%s fa",
489
+ s = "qualche secondo",
490
+ m = "un minuto",
491
+ mm = "%d minuti",
492
+ h = "un'ora",
493
+ hh = "%d ore",
494
+ d = "un giorno",
495
+ dd = "%d giorni",
496
+ M = "un mese",
497
+ MM = "%d mesi",
498
+ y = "un anno",
499
+ yy = "%d anni",
500
+ },
501
+ duration = {
502
+ years = { one = "%d anno", other = "%d anni" },
503
+ months = { one = "%d mese", other = "%d mesi" },
504
+ weeks = { one = "%d settimana", other = "%d settimane" },
505
+ days = { one = "%d giorno", other = "%d giorni" },
506
+ hours = { one = "%d ora", other = "%d ore" },
507
+ minutes = { one = "%d minuto", other = "%d minuti" },
508
+ seconds = { one = "%d secondo", other = "%d secondi" },
509
+ milliseconds = { one = "%d millisecondo", other = "%d millisecondi" },
510
+ },
511
+ },
512
+
513
+ ru = {
514
+ calendar = {
515
+ sameDay = "[Сегодня, в] LT",
516
+ nextDay = "[Завтра, в] LT",
517
+ nextWeek = "[В следующий] dddd, [в] LT",
518
+ lastDay = "[Вчера, в] LT",
519
+ lastWeek = "[В прошлый] dddd, [в] LT",
520
+ sameElse = "L",
521
+ },
522
+ relativeTime = {
523
+ future = "через %s",
524
+ past = "%s назад",
525
+ s = "несколько секунд",
526
+ m = TimeLocalizationUtils._russianRelative,
527
+ mm = TimeLocalizationUtils._russianRelative,
528
+ h = "час",
529
+ hh = TimeLocalizationUtils._russianRelative,
530
+ d = "день",
531
+ dd = TimeLocalizationUtils._russianRelative,
532
+ M = "месяц",
533
+ MM = TimeLocalizationUtils._russianRelative,
534
+ y = "год",
535
+ yy = TimeLocalizationUtils._russianRelative,
536
+ },
537
+ duration = {
538
+ years = TimeLocalizationUtils._russianDuration("год", "года", "лет"),
539
+ months = TimeLocalizationUtils._russianDuration("месяц", "месяца", "месяцев"),
540
+ weeks = TimeLocalizationUtils._russianDuration("неделя", "недели", "недель"),
541
+ days = TimeLocalizationUtils._russianDuration("день", "дня", "дней"),
542
+ hours = TimeLocalizationUtils._russianDuration("час", "часа", "часов"),
543
+ minutes = TimeLocalizationUtils._russianDuration("минута", "минуты", "минут"),
544
+ seconds = TimeLocalizationUtils._russianDuration("секунда", "секунды", "секунд"),
545
+ milliseconds = TimeLocalizationUtils._russianDuration(
546
+ "миллисекунда",
547
+ "миллисекунды",
548
+ "миллисекунд"
549
+ ),
550
+ },
551
+ },
552
+
553
+ pl = {
554
+ calendar = {
555
+ sameDay = "[Dziś o] LT",
556
+ nextDay = "[Jutro o] LT",
557
+ nextWeek = "[W] dddd [o] LT",
558
+ lastDay = "[Wczoraj o] LT",
559
+ lastWeek = "[W zeszły] dddd [o] LT",
560
+ sameElse = "L",
561
+ },
562
+ relativeTime = {
563
+ future = "za %s",
564
+ past = "%s temu",
565
+ s = "kilka sekund",
566
+ m = TimeLocalizationUtils._polishRelative,
567
+ mm = TimeLocalizationUtils._polishRelative,
568
+ h = TimeLocalizationUtils._polishRelative,
569
+ hh = TimeLocalizationUtils._polishRelative,
570
+ d = "1 dzień",
571
+ dd = "%d dni",
572
+ M = "miesiąc",
573
+ MM = TimeLocalizationUtils._polishRelative,
574
+ y = "rok",
575
+ yy = TimeLocalizationUtils._polishRelative,
576
+ },
577
+ duration = {
578
+ years = TimeLocalizationUtils._polishDuration("rok", "lata", "lat"),
579
+ months = TimeLocalizationUtils._polishDuration("miesiąc", "miesiące", "miesięcy"),
580
+ weeks = TimeLocalizationUtils._polishDuration("tydzień", "tygodnie", "tygodni"),
581
+ days = TimeLocalizationUtils._polishDuration("dzień", "dni", "dni"),
582
+ hours = TimeLocalizationUtils._polishDuration("godzina", "godziny", "godzin"),
583
+ minutes = TimeLocalizationUtils._polishDuration("minuta", "minuty", "minut"),
584
+ seconds = TimeLocalizationUtils._polishDuration("sekunda", "sekundy", "sekund"),
585
+ milliseconds = TimeLocalizationUtils._polishDuration("milisekunda", "milisekundy", "milisekund"),
586
+ },
587
+ },
588
+
589
+ tr = {
590
+ calendar = {
591
+ sameDay = "[bugün saat] LT",
592
+ nextDay = "[yarın saat] LT",
593
+ nextWeek = "[gelecek] dddd [saat] LT",
594
+ lastDay = "[dün] LT",
595
+ lastWeek = "[geçen] dddd [saat] LT",
596
+ sameElse = "L",
597
+ },
598
+ relativeTime = {
599
+ future = "%s sonra",
600
+ past = "%s önce",
601
+ s = "birkaç saniye",
602
+ m = "bir dakika",
603
+ mm = "%d dakika",
604
+ h = "bir saat",
605
+ hh = "%d saat",
606
+ d = "bir gün",
607
+ dd = "%d gün",
608
+ M = "bir ay",
609
+ MM = "%d ay",
610
+ y = "bir yıl",
611
+ yy = "%d yıl",
612
+ },
613
+ duration = {
614
+ years = TimeLocalizationUtils._invariantPhrase("%d yıl"),
615
+ months = TimeLocalizationUtils._invariantPhrase("%d ay"),
616
+ weeks = TimeLocalizationUtils._invariantPhrase("%d hafta"),
617
+ days = TimeLocalizationUtils._invariantPhrase("%d gün"),
618
+ hours = TimeLocalizationUtils._invariantPhrase("%d saat"),
619
+ minutes = TimeLocalizationUtils._invariantPhrase("%d dakika"),
620
+ seconds = TimeLocalizationUtils._invariantPhrase("%d saniye"),
621
+ milliseconds = TimeLocalizationUtils._invariantPhrase("%d milisaniye"),
622
+ },
623
+ },
624
+
625
+ id = {
626
+ calendar = {
627
+ sameDay = "[Hari ini pukul] LT",
628
+ nextDay = "[Besok pukul] LT",
629
+ nextWeek = "dddd [pukul] LT",
630
+ lastDay = "[Kemarin pukul] LT",
631
+ lastWeek = "dddd [lalu pukul] LT",
632
+ sameElse = "L",
633
+ },
634
+ relativeTime = {
635
+ future = "dalam %s",
636
+ past = "%s yang lalu",
637
+ s = "beberapa detik",
638
+ m = "semenit",
639
+ mm = "%d menit",
640
+ h = "sejam",
641
+ hh = "%d jam",
642
+ d = "sehari",
643
+ dd = "%d hari",
644
+ M = "sebulan",
645
+ MM = "%d bulan",
646
+ y = "setahun",
647
+ yy = "%d tahun",
648
+ },
649
+ duration = {
650
+ years = TimeLocalizationUtils._invariantPhrase("%d tahun"),
651
+ months = TimeLocalizationUtils._invariantPhrase("%d bulan"),
652
+ weeks = TimeLocalizationUtils._invariantPhrase("%d minggu"),
653
+ days = TimeLocalizationUtils._invariantPhrase("%d hari"),
654
+ hours = TimeLocalizationUtils._invariantPhrase("%d jam"),
655
+ minutes = TimeLocalizationUtils._invariantPhrase("%d menit"),
656
+ seconds = TimeLocalizationUtils._invariantPhrase("%d detik"),
657
+ milliseconds = TimeLocalizationUtils._invariantPhrase("%d milidetik"),
658
+ },
659
+ },
660
+
661
+ vi = {
662
+ calendar = {
663
+ sameDay = "[Hôm nay lúc] LT",
664
+ nextDay = "[Ngày mai lúc] LT",
665
+ nextWeek = "dddd [tuần tới lúc] LT",
666
+ lastDay = "[Hôm qua lúc] LT",
667
+ lastWeek = "dddd [tuần trước lúc] LT",
668
+ sameElse = "L",
669
+ },
670
+ relativeTime = {
671
+ future = "%s tới",
672
+ past = "%s trước",
673
+ s = "vài giây",
674
+ m = "một phút",
675
+ mm = "%d phút",
676
+ h = "một giờ",
677
+ hh = "%d giờ",
678
+ d = "một ngày",
679
+ dd = "%d ngày",
680
+ M = "một tháng",
681
+ MM = "%d tháng",
682
+ y = "một năm",
683
+ yy = "%d năm",
684
+ },
685
+ duration = {
686
+ years = TimeLocalizationUtils._invariantPhrase("%d năm"),
687
+ months = TimeLocalizationUtils._invariantPhrase("%d tháng"),
688
+ weeks = TimeLocalizationUtils._invariantPhrase("%d tuần"),
689
+ days = TimeLocalizationUtils._invariantPhrase("%d ngày"),
690
+ hours = TimeLocalizationUtils._invariantPhrase("%d giờ"),
691
+ minutes = TimeLocalizationUtils._invariantPhrase("%d phút"),
692
+ seconds = TimeLocalizationUtils._invariantPhrase("%d giây"),
693
+ milliseconds = TimeLocalizationUtils._invariantPhrase("%d mili giây"),
694
+ },
695
+ },
696
+
697
+ th = {
698
+ calendar = {
699
+ sameDay = "[วันนี้ เวลา] LT",
700
+ nextDay = "[พรุ่งนี้ เวลา] LT",
701
+ nextWeek = "dddd[หน้า เวลา] LT",
702
+ lastDay = "[เมื่อวานนี้ เวลา] LT",
703
+ lastWeek = "[วัน]dddd[ที่แล้ว เวลา] LT",
704
+ sameElse = "L",
705
+ },
706
+ relativeTime = {
707
+ future = "อีก %s",
708
+ past = "%sที่แล้ว",
709
+ s = "ไม่กี่วินาที",
710
+ m = "1 นาที",
711
+ mm = "%d นาที",
712
+ h = "1 ชั่วโมง",
713
+ hh = "%d ชั่วโมง",
714
+ d = "1 วัน",
715
+ dd = "%d วัน",
716
+ M = "1 เดือน",
717
+ MM = "%d เดือน",
718
+ y = "1 ปี",
719
+ yy = "%d ปี",
720
+ },
721
+ duration = {
722
+ years = TimeLocalizationUtils._invariantPhrase("%d ปี"),
723
+ months = TimeLocalizationUtils._invariantPhrase("%d เดือน"),
724
+ weeks = TimeLocalizationUtils._invariantPhrase("%d สัปดาห์"),
725
+ days = TimeLocalizationUtils._invariantPhrase("%d วัน"),
726
+ hours = TimeLocalizationUtils._invariantPhrase("%d ชั่วโมง"),
727
+ minutes = TimeLocalizationUtils._invariantPhrase("%d นาที"),
728
+ seconds = TimeLocalizationUtils._invariantPhrase("%d วินาที"),
729
+ milliseconds = TimeLocalizationUtils._invariantPhrase("%d มิลลิวินาที"),
730
+ },
731
+ },
732
+
733
+ ar = {
734
+ calendar = {
735
+ sameDay = "[اليوم عند الساعة] LT",
736
+ nextDay = "[غدًا عند الساعة] LT",
737
+ nextWeek = "dddd [عند الساعة] LT",
738
+ lastDay = "[أمس عند الساعة] LT",
739
+ lastWeek = "dddd [عند الساعة] LT",
740
+ sameElse = "L",
741
+ },
742
+ relativeTime = {
743
+ future = "بعد %s",
744
+ past = "منذ %s",
745
+ s = "ثانية واحدة",
746
+ m = "دقيقة واحدة",
747
+ mm = "%d دقائق",
748
+ h = "ساعة واحدة",
749
+ hh = "%d ساعات",
750
+ d = "يوم واحد",
751
+ dd = "%d أيام",
752
+ M = "شهر واحد",
753
+ MM = "%d أشهر",
754
+ y = "عام واحد",
755
+ yy = "%d أعوام",
756
+ },
757
+ duration = {
758
+ years = { one = "%d سنة", other = "%d سنوات" },
759
+ months = { one = "%d شهر", other = "%d أشهر" },
760
+ weeks = { one = "%d أسبوع", other = "%d أسابيع" },
761
+ days = { one = "%d يوم", other = "%d أيام" },
762
+ hours = { one = "%d ساعة", other = "%d ساعات" },
763
+ minutes = { one = "%d دقيقة", other = "%d دقائق" },
764
+ seconds = { one = "%d ثانية", other = "%d ثوان" },
765
+ milliseconds = { one = "%d مللي ثانية", other = "%d مللي ثانية" },
766
+ },
767
+ },
768
+
769
+ ["zh-cn"] = {
770
+ calendar = {
771
+ sameDay = "[今天]LT",
772
+ nextDay = "[明天]LT",
773
+ nextWeek = "[下]dddLT",
774
+ lastDay = "[昨天]LT",
775
+ lastWeek = "[上]dddLT",
776
+ sameElse = "L",
777
+ },
778
+ relativeTime = {
779
+ future = "%s内",
780
+ past = "%s前",
781
+ s = "几秒",
782
+ m = "1 分钟",
783
+ mm = "%d 分钟",
784
+ h = "1 小时",
785
+ hh = "%d 小时",
786
+ d = "1 天",
787
+ dd = "%d 天",
788
+ M = "1 个月",
789
+ MM = "%d 个月",
790
+ y = "1 年",
791
+ yy = "%d 年",
792
+ },
793
+ duration = {
794
+ years = TimeLocalizationUtils._invariantPhrase("%d 年"),
795
+ months = TimeLocalizationUtils._invariantPhrase("%d 个月"),
796
+ weeks = TimeLocalizationUtils._invariantPhrase("%d 周"),
797
+ days = TimeLocalizationUtils._invariantPhrase("%d 天"),
798
+ hours = TimeLocalizationUtils._invariantPhrase("%d 小时"),
799
+ minutes = TimeLocalizationUtils._invariantPhrase("%d 分钟"),
800
+ seconds = TimeLocalizationUtils._invariantPhrase("%d 秒"),
801
+ milliseconds = TimeLocalizationUtils._invariantPhrase("%d 毫秒"),
802
+ },
803
+ },
804
+
805
+ ["zh-tw"] = {
806
+ calendar = {
807
+ sameDay = "[今天] LT",
808
+ nextDay = "[明天] LT",
809
+ nextWeek = "[下]dddd LT",
810
+ lastDay = "[昨天] LT",
811
+ lastWeek = "[上]dddd LT",
812
+ sameElse = "L",
813
+ },
814
+ relativeTime = {
815
+ future = "%s後",
816
+ past = "%s前",
817
+ s = "幾秒",
818
+ m = "1 分鐘",
819
+ mm = "%d 分鐘",
820
+ h = "1 小時",
821
+ hh = "%d 小時",
822
+ d = "1 天",
823
+ dd = "%d 天",
824
+ M = "1 個月",
825
+ MM = "%d 個月",
826
+ y = "1 年",
827
+ yy = "%d 年",
828
+ },
829
+ duration = {
830
+ years = TimeLocalizationUtils._invariantPhrase("%d 年"),
831
+ months = TimeLocalizationUtils._invariantPhrase("%d 個月"),
832
+ weeks = TimeLocalizationUtils._invariantPhrase("%d 週"),
833
+ days = TimeLocalizationUtils._invariantPhrase("%d 天"),
834
+ hours = TimeLocalizationUtils._invariantPhrase("%d 小時"),
835
+ minutes = TimeLocalizationUtils._invariantPhrase("%d 分鐘"),
836
+ seconds = TimeLocalizationUtils._invariantPhrase("%d 秒"),
837
+ milliseconds = TimeLocalizationUtils._invariantPhrase("%d 毫秒"),
838
+ },
839
+ },
840
+
841
+ ko = {
842
+ calendar = {
843
+ sameDay = "[오늘] LT",
844
+ nextDay = "[내일] LT",
845
+ nextWeek = "dddd LT",
846
+ lastDay = "[어제] LT",
847
+ lastWeek = "[지난주] dddd LT",
848
+ sameElse = "L",
849
+ },
850
+ relativeTime = {
851
+ future = "%s 후",
852
+ past = "%s 전",
853
+ s = "몇 초",
854
+ m = "1분",
855
+ mm = "%d분",
856
+ h = "한 시간",
857
+ hh = "%d시간",
858
+ d = "하루",
859
+ dd = "%d일",
860
+ M = "한 달",
861
+ MM = "%d달",
862
+ y = "일 년",
863
+ yy = "%d년",
864
+ },
865
+ duration = {
866
+ years = TimeLocalizationUtils._invariantPhrase("%d년"),
867
+ months = TimeLocalizationUtils._invariantPhrase("%d개월"),
868
+ weeks = TimeLocalizationUtils._invariantPhrase("%d주"),
869
+ days = TimeLocalizationUtils._invariantPhrase("%d일"),
870
+ hours = TimeLocalizationUtils._invariantPhrase("%d시간"),
871
+ minutes = TimeLocalizationUtils._invariantPhrase("%d분"),
872
+ seconds = TimeLocalizationUtils._invariantPhrase("%d초"),
873
+ milliseconds = TimeLocalizationUtils._invariantPhrase("%d밀리초"),
874
+ },
875
+ },
876
+
877
+ ja = {
878
+ calendar = {
879
+ sameDay = "[今日] LT",
880
+ nextDay = "[明日] LT",
881
+ nextWeek = "[来週]dddd LT",
882
+ lastDay = "[昨日] LT",
883
+ lastWeek = "[先週]dddd LT",
884
+ sameElse = "L",
885
+ },
886
+ relativeTime = {
887
+ future = "%s後",
888
+ past = "%s前",
889
+ s = "数秒",
890
+ m = "1分",
891
+ mm = "%d分",
892
+ h = "1時間",
893
+ hh = "%d時間",
894
+ d = "1日",
895
+ dd = "%d日",
896
+ M = "1ヶ月",
897
+ MM = "%dヶ月",
898
+ y = "1年",
899
+ yy = "%d年",
900
+ },
901
+ duration = {
902
+ years = TimeLocalizationUtils._invariantPhrase("%d年"),
903
+ months = TimeLocalizationUtils._invariantPhrase("%dヶ月"),
904
+ weeks = TimeLocalizationUtils._invariantPhrase("%d週間"),
905
+ days = TimeLocalizationUtils._invariantPhrase("%d日"),
906
+ hours = TimeLocalizationUtils._invariantPhrase("%d時間"),
907
+ minutes = TimeLocalizationUtils._invariantPhrase("%d分"),
908
+ seconds = TimeLocalizationUtils._invariantPhrase("%d秒"),
909
+ milliseconds = TimeLocalizationUtils._invariantPhrase("%dミリ秒"),
910
+ },
911
+ },
912
+ }
913
+
914
+ for _, locale in pairs(LOCALES) do
915
+ table.freeze(locale.calendar)
916
+ table.freeze(locale.relativeTime)
917
+ table.freeze(locale.duration)
918
+ table.freeze(locale)
919
+ end
920
+
921
+ -- Roblox's Simplified Chinese variant id, same strings as zh-cn
922
+ LOCALES["zh-cjv"] = LOCALES["zh-cn"]
923
+
924
+ --[=[
925
+ Returns the read-only [TimeLocale] for a locale, defaulting to English.
926
+ ]=]
927
+ function TimeLocalizationUtils.getLocale(locale: string?): TimeLocale
928
+ local key = ResolveLocaleUtils.resolveClosestKey(locale or DEFAULT_LOCALE, LOCALES)
929
+ if key then
930
+ return LOCALES[key]
931
+ end
932
+
933
+ warn(
934
+ string.format(
935
+ "[TimeLocalizationUtils] - No strings for locale '%s', reverting to '%s' instead.",
936
+ tostring(locale),
937
+ DEFAULT_LOCALE
938
+ )
939
+ )
940
+ return LOCALES[ResolveLocaleUtils.resolveClosestKey(DEFAULT_LOCALE, LOCALES) :: string]
941
+ end
942
+
943
+ --[=[
944
+ Returns the read-only [CalendarFormats] for a locale, defaulting to English.
945
+ ]=]
946
+ function TimeLocalizationUtils.getCalendarFormatsForLocale(locale: string?): CalendarFormats
947
+ return TimeLocalizationUtils.getLocale(locale).calendar
948
+ end
949
+
950
+ --[=[
951
+ Returns the read-only [RelativeTimeStrings] for a locale, defaulting to English.
952
+ ]=]
953
+ function TimeLocalizationUtils.getRelativeTimeStringsForLocale(locale: string?): RelativeTimeStrings
954
+ return TimeLocalizationUtils.getLocale(locale).relativeTime
955
+ end
956
+
957
+ --[=[
958
+ Returns the read-only [DurationStrings] for a locale, defaulting to English.
959
+ ]=]
960
+ function TimeLocalizationUtils.getDurationStringsForLocale(locale: string?): DurationStrings
961
+ return TimeLocalizationUtils.getLocale(locale).duration
962
+ end
963
+
964
+ return TimeLocalizationUtils