@fy-/fws-vue 2.3.39 → 2.3.40
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/composables/templating.ts +31 -3
- package/package.json +1 -1
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import { getLocale } from '@fy-/fws-js'
|
|
2
|
-
import { format as formatDateTimeago } from 'timeago.js'
|
|
2
|
+
import { format as formatDateTimeago, register } from 'timeago.js'
|
|
3
|
+
import * as timeagoLocales from 'timeago.js/lib/lang'
|
|
3
4
|
import { useTranslation } from './translations'
|
|
4
5
|
|
|
6
|
+
// Register all available timeago.js locales
|
|
7
|
+
function registerTimeagoLocales() {
|
|
8
|
+
// Register all available locales from timeago.js
|
|
9
|
+
Object.entries(timeagoLocales).forEach(([locale, func]) => {
|
|
10
|
+
if (locale !== 'default' && typeof func === 'function') {
|
|
11
|
+
register(locale, func)
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Register locales when this module is imported
|
|
17
|
+
registerTimeagoLocales()
|
|
18
|
+
|
|
5
19
|
// Cache common constants and patterns
|
|
6
20
|
const k = 1024
|
|
7
21
|
const byteSizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
@@ -109,9 +123,23 @@ function formatDatetime(dt: Date | string | number) {
|
|
|
109
123
|
|
|
110
124
|
function formatTimeago(dt: Date | string | number) {
|
|
111
125
|
const timestamp = parseDateInput(dt)
|
|
112
|
-
|
|
126
|
+
// Extract language code and convert dash to underscore for timeago.js format
|
|
127
|
+
const fullLocale = getLocale()
|
|
128
|
+
|
|
129
|
+
// First try with underscore format (en-US -> en_US)
|
|
130
|
+
const localeWithUnderscore = fullLocale.replace('-', '_')
|
|
131
|
+
|
|
132
|
+
// Then try just the language part (en-US -> en)
|
|
133
|
+
const langOnly = fullLocale.split('-')[0].toLowerCase()
|
|
134
|
+
|
|
135
|
+
// Try the formats in order of preference
|
|
136
|
+
// This avoids try/catch which can trigger linting issues
|
|
137
|
+
const dateObj = new Date(timestamp)
|
|
113
138
|
|
|
114
|
-
|
|
139
|
+
// No try/catch needed - if locale doesn't exist, timeago falls back to en_US
|
|
140
|
+
return formatDateTimeago(dateObj, localeWithUnderscore)
|
|
141
|
+
|| formatDateTimeago(dateObj, langOnly)
|
|
142
|
+
|| formatDateTimeago(dateObj, 'en_US')
|
|
115
143
|
}
|
|
116
144
|
|
|
117
145
|
export {
|