@fy-/fws-vue 2.3.40 → 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,20 +1,32 @@
1
1
  import { getLocale } from '@fy-/fws-js'
2
2
  import { format as formatDateTimeago, register } from 'timeago.js'
3
- import * as timeagoLocales from 'timeago.js/lib/lang'
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'
4
12
  import { useTranslation } from './translations'
5
13
 
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()
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)
18
30
 
19
31
  // Cache common constants and patterns
20
32
  const k = 1024
@@ -123,23 +135,17 @@ function formatDatetime(dt: Date | string | number) {
123
135
 
124
136
  function formatTimeago(dt: Date | string | number) {
125
137
  const timestamp = parseDateInput(dt)
126
- // 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
127
141
  const fullLocale = getLocale()
128
142
 
129
- // First try with underscore format (en-US -> en_US)
143
+ // Convert locale format (e.g., fr-FR to fr_FR)
130
144
  const localeWithUnderscore = fullLocale.replace('-', '_')
131
145
 
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)
138
-
139
- // 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
140
148
  return formatDateTimeago(dateObj, localeWithUnderscore)
141
- || formatDateTimeago(dateObj, langOnly)
142
- || formatDateTimeago(dateObj, 'en_US')
143
149
  }
144
150
 
145
151
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fy-/fws-vue",
3
- "version": "2.3.40",
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",