@fy-/fws-vue 2.3.38 → 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.
@@ -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
- const locale = getLocale().replace('_', '-')
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
- return formatDateTimeago(new Date(timestamp), locale)
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fy-/fws-vue",
3
- "version": "2.3.38",
3
+ "version": "2.3.40",
4
4
  "author": "Florian 'Fy' Gasquez <m@fy.to>",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/fy-to/FWJS#readme",