@fy-/fws-vue 2.3.41 → 2.3.42

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,33 @@
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 de from 'timeago.js/esm/lang/de'
4
+ import es from 'timeago.js/esm/lang/es'
5
+ // Import common locales individually to avoid CommonJS issues
6
+ import fr from 'timeago.js/esm/lang/fr'
7
+ import it from 'timeago.js/esm/lang/it'
8
+ import ja from 'timeago.js/esm/lang/ja'
9
+ import nl from 'timeago.js/esm/lang/nl'
10
+ import ru from 'timeago.js/esm/lang/ru'
11
+ import zh_CN from 'timeago.js/esm/lang/zh_CN'
3
12
  import { useTranslation } from './translations'
4
13
 
14
+ // Register common locales
15
+ register('fr', fr)
16
+ register('fr_FR', fr)
17
+ register('es', es)
18
+ register('es_ES', es)
19
+ register('de', de)
20
+ register('de_DE', de)
21
+ register('it', it)
22
+ register('it_IT', it)
23
+ register('nl', nl)
24
+ register('nl_NL', nl)
25
+ register('ru', ru)
26
+ register('ru_RU', ru)
27
+ register('ja', ja)
28
+ register('ja_JP', ja)
29
+ register('zh_CN', zh_CN)
30
+
5
31
  // Cache common constants and patterns
6
32
  const k = 1024
7
33
  const byteSizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
@@ -109,23 +135,17 @@ function formatDatetime(dt: Date | string | number) {
109
135
 
110
136
  function formatTimeago(dt: Date | string | number) {
111
137
  const timestamp = parseDateInput(dt)
112
- // Extract language code and convert dash to underscore for timeago.js format
138
+ const dateObj = new Date(timestamp)
139
+
140
+ // Get browser locale and format it for timeago.js
113
141
  const fullLocale = getLocale()
114
142
 
115
- // First try with underscore format (en-US -> en_US)
143
+ // Convert locale format (e.g., fr-FR to fr_FR)
116
144
  const localeWithUnderscore = fullLocale.replace('-', '_')
117
145
 
118
- // Then try just the language part (en-US -> en)
119
- const langOnly = fullLocale.split('-')[0].toLowerCase()
120
-
121
- // Try the formats in order of preference
122
- // This avoids try/catch which can trigger linting issues
123
- const dateObj = new Date(timestamp)
124
-
125
- // No try/catch needed - if locale doesn't exist, timeago falls back to en_US
146
+ // Use the locale directly - the registration above ensures support
147
+ // timeago.js will fall back to en_US if no matching locale is found
126
148
  return formatDateTimeago(dateObj, localeWithUnderscore)
127
- || formatDateTimeago(dateObj, langOnly)
128
- || formatDateTimeago(dateObj, 'en_US')
129
149
  }
130
150
 
131
151
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fy-/fws-vue",
3
- "version": "2.3.41",
3
+ "version": "2.3.42",
4
4
  "author": "Florian 'Fy' Gasquez <m@fy.to>",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/fy-to/FWJS#readme",