adminforth 2.4.0-next.276 → 2.4.0-next.277

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.
@@ -10,7 +10,7 @@
10
10
  "build-only": "vite build",
11
11
  "type-check": "vue-tsc --build --force",
12
12
  "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
13
- "i18n:extract": "echo {} > i18n-empty.json && vue-i18n-extract report --vueFiles \"./src/**/*.{js,vue}\" --output ./i18n-messages.json --languageFiles \"i18n-empty.json\" --add"
13
+ "i18n:extract": "echo {} > i18n-empty.json && vue-i18n-extract report --vueFiles \"./src/**/*.{js,vue,ts}\" --output ./i18n-messages.json --languageFiles \"i18n-empty.json\" --add"
14
14
  },
15
15
  "dependencies": {
16
16
  "@iconify-prerendered/vue-flag": "^0.28.1748584105",
@@ -7,7 +7,7 @@ function slavicPluralRule(choice: number, choicesLength: number, orgRule: any) {
7
7
  if (choice === 0) {
8
8
  return 0
9
9
  }
10
-
10
+
11
11
  const teen = choice > 10 && choice < 20
12
12
  const endsWithOne = choice % 10 === 1
13
13
 
@@ -21,6 +21,8 @@ function slavicPluralRule(choice: number, choicesLength: number, orgRule: any) {
21
21
  return choicesLength < 4 ? 2 : 3
22
22
  }
23
23
 
24
+ export let i18nInstance: ReturnType<typeof createI18n> | null = null
25
+
24
26
  export function initI18n(app: ReturnType<typeof createApp>) {
25
27
  const i18n = createI18n({
26
28
  legacy: false,
@@ -48,7 +50,7 @@ export function initI18n(app: ReturnType<typeof createApp>) {
48
50
  return key + ' ';
49
51
  },
50
52
  });
51
-
52
53
  app.use(i18n);
54
+ i18nInstance = i18n
53
55
  return i18n
54
56
  }
@@ -14,7 +14,7 @@ app.use(createPinia())
14
14
  app.use(router)
15
15
 
16
16
  // get access to i18n instance outside components
17
- window.i18n = initI18n(app);
17
+ initI18n(app);
18
18
 
19
19
 
20
20
  /* IMPORTANT:ADMINFORTH CUSTOM USES */
@@ -9,6 +9,7 @@ import adminforth from './adminforth';
9
9
  import sanitizeHtml from 'sanitize-html'
10
10
  import debounce from 'debounce';
11
11
  import type { AdminForthResourceColumnInputCommon, Predicate } from '@/types/Common';
12
+ import { i18nInstance } from './i18n'
12
13
 
13
14
  const LS_LANG_KEY = `afLanguage`;
14
15
  const MAX_CONSECUTIVE_EMPTY_RESULTS = 2;
@@ -19,6 +20,7 @@ export async function callApi({path, method, body, headers}: {
19
20
  body?: any
20
21
  headers?: Record<string, string>
21
22
  }): Promise<any> {
23
+ const t = i18nInstance?.global.t || ((s: string) => s)
22
24
  const options = {
23
25
  method,
24
26
  headers: {
@@ -42,11 +44,11 @@ export async function callApi({path, method, body, headers}: {
42
44
  // if it is internal error, say to user
43
45
  if (e instanceof TypeError && e.message === 'Failed to fetch') {
44
46
  // this is a network error
45
- adminforth.alert({variant:'danger', message: window.i18n?.global?.t('Network error, please check your Internet connection and try again'),})
47
+ adminforth.alert({variant:'danger', message: t('Network error, please check your Internet connection and try again'),})
46
48
  return null;
47
49
  }
48
50
 
49
- adminforth.alert({variant:'danger', message: window.i18n?.global?.t('Something went wrong, please try again later'),})
51
+ adminforth.alert({variant:'danger', message: t('Something went wrong, please try again later'),})
50
52
  console.error(`error in callApi ${path}`, e);
51
53
  }
52
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "2.4.0-next.276",
3
+ "version": "2.4.0-next.277",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",