From 58404e1fce807ca99e4b5f971dc2abf8a4e488ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Fern=C3=A1ndez?= Date: Wed, 7 May 2025 15:09:46 +0200 Subject: [PATCH] fix(i18n): re-fix types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fernando Fernández --- .vscode/settings.json | 7 ++++- frontend/tsconfig.json | 1 + package-lock.json | 2 ++ packages/i18n/index.d.ts | 2 ++ packages/i18n/package.json | 7 +++-- packages/i18n/src/index.ts | 12 ++++----- packages/i18n/tsconfig.json | 4 +-- packages/i18n/types.d.ts | 34 ------------------------ packages/i18n/types/i18next.d.ts | 16 +++++++++++ packages/i18n/types/virtual-modules.d.ts | 19 +++++++++++++ packages/ui-toolkit/package.json | 1 + packages/ui-toolkit/tsconfig.json | 1 + 12 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 packages/i18n/index.d.ts delete mode 100644 packages/i18n/types.d.ts create mode 100644 packages/i18n/types/i18next.d.ts create mode 100644 packages/i18n/types/virtual-modules.d.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 369940e2..afe8f6fc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,11 +17,16 @@ "i18n-ally.keystyle": "flat", "i18n-ally.sortKeys": true, "i18n-ally.sourceLanguage": "en", + "i18n-ally.includeSubfolders": false, + "i18n-ally.fullReloadOnChanged": true, + "i18n-ally.extract.autoDetect": true, + "i18n-ally.annotations": false, "i18n-ally.localesPaths": [ "packages/i18n/strings" ], "i18n-ally.enabledFrameworks": [ - "vue" + "i18next", + "vue-sfc" ], "eslint.validate": [ "vue", diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 11d57341..e260f530 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -8,6 +8,7 @@ ], "types": [ "axios", + "@jellyfin-vue/i18n", "unplugin-vue-router/client", "vite/client", "vuetify", diff --git a/package-lock.json b/package-lock.json index 26fb0feb..b7da4bfc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -81,6 +81,7 @@ "@storybook/blocks": "*", "@storybook/vue3": "*", "@storybook/vue3-vite": "*", + "@vue/shared": "*", "storybook": "*", "type-fest": "*", "vite": "*" @@ -13735,6 +13736,7 @@ "@jellyfin-vue/configs": "*" }, "peerDependencies": { + "@jellyfin-vue/i18n": "*", "@vueuse/core": "*", "comlink": "*", "i18next-vue": "*", diff --git a/packages/i18n/index.d.ts b/packages/i18n/index.d.ts new file mode 100644 index 00000000..f05f4a13 --- /dev/null +++ b/packages/i18n/index.d.ts @@ -0,0 +1,2 @@ +import './types/i18next.d.ts'; +import './types/virtual-modules.d.ts'; diff --git a/packages/i18n/package.json b/packages/i18n/package.json index 28489533..631b69c3 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -2,11 +2,14 @@ "name": "@jellyfin-vue/i18n", "type": "module", "description": "All internacionalization files for Jellyfin Vue", - "types": "./types.d.ts", "exports": { - ".": "./src/index.ts", + ".": { + "import": "./src/index.ts", + "types": "./index.d.ts" + }, "./vite": "./src/vite.ts" }, + "scripts": { "lint": "eslint .", "lint:fix": "eslint . --fix", diff --git a/packages/i18n/src/index.ts b/packages/i18n/src/index.ts index 7b0f6737..2ddf9ef0 100644 --- a/packages/i18n/src/index.ts +++ b/packages/i18n/src/index.ts @@ -16,13 +16,13 @@ await i18next type: 'backend', init: NOOP, read: (language, _, done) => { - const promise = resources[language] as Promise>; + const loadFn = resources[language]; - void (async () => { - const data = await promise; - - done(undefined, data); - })(); + if (loadFn) { + void (async () => done(undefined, await loadFn()))(); + } else { + done(new Error(`Language ${language} not found`), {}); + } } } satisfies BackendModule) .init({ diff --git a/packages/i18n/tsconfig.json b/packages/i18n/tsconfig.json index b9c8f783..6043f26e 100644 --- a/packages/i18n/tsconfig.json +++ b/packages/i18n/tsconfig.json @@ -14,8 +14,8 @@ "coverage" ], "include": [ - "*.d.ts", - "*.ts", + "**/*.d.ts", + "**/*.ts", "src/*.ts", "**/*.json" ], diff --git a/packages/i18n/types.d.ts b/packages/i18n/types.d.ts deleted file mode 100644 index 3dd7b492..00000000 --- a/packages/i18n/types.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type en from './strings/en.json'; - -type Resources = Record Promise>; - -declare module 'i18next' { - interface CustomTypeOptions { - resources: Resources; - strictKeyChecks: true; - } -} - -declare module 'virtual:locales/date-fns' { - import * as locales from 'date-fns/locale'; - - export = locales; -} - -declare module 'virtual:locales/vuetify' { - import type * as locales from 'vuetify/locale'; - - const typeWithoutRtl: Omit; - - export = typeWithoutRtl; -} - -declare module 'virtual:i18next/resources' { - export const resources: Resources; -} - -/** - * This is important: https://stackoverflow.com/a/64189046 - * https://www.typescriptlang.org/docs/handbook/modules.html - */ -export { }; diff --git a/packages/i18n/types/i18next.d.ts b/packages/i18n/types/i18next.d.ts new file mode 100644 index 00000000..92936328 --- /dev/null +++ b/packages/i18n/types/i18next.d.ts @@ -0,0 +1,16 @@ +import type en from '../strings/en.json'; + +export type LanguageKeys = typeof en; + +declare module 'i18next' { + interface CustomTypeOptions { + resources: Record; + strictKeyChecks: true; + } +} + +/** + * This is important: https://stackoverflow.com/a/64189046 + * https://www.typescriptlang.org/docs/handbook/modules.html + */ +export { }; diff --git a/packages/i18n/types/virtual-modules.d.ts b/packages/i18n/types/virtual-modules.d.ts new file mode 100644 index 00000000..2f127455 --- /dev/null +++ b/packages/i18n/types/virtual-modules.d.ts @@ -0,0 +1,19 @@ +declare module 'virtual:locales/date-fns' { + import * as locales from 'date-fns/locale'; + + export = locales; +} + +declare module 'virtual:locales/vuetify' { + import type * as locales from 'vuetify/locale'; + + const typeWithoutRtl: BetterOmit; + + export = typeWithoutRtl; +} + +declare module 'virtual:i18next/resources' { + import type { LanguageKeys } from './types/i18next'; + + export const resources: Record Promise>>; +} diff --git a/packages/ui-toolkit/package.json b/packages/ui-toolkit/package.json index 697ce3c4..6a6dd106 100644 --- a/packages/ui-toolkit/package.json +++ b/packages/ui-toolkit/package.json @@ -26,6 +26,7 @@ "@jellyfin-vue/configs": "*" }, "peerDependencies": { + "@jellyfin-vue/i18n": "*", "@vueuse/core": "*", "comlink": "*", "i18next-vue": "*", diff --git a/packages/ui-toolkit/tsconfig.json b/packages/ui-toolkit/tsconfig.json index b02d1c38..d6bf5c84 100644 --- a/packages/ui-toolkit/tsconfig.json +++ b/packages/ui-toolkit/tsconfig.json @@ -7,6 +7,7 @@ "DOM" ], "types": [ + "@jellyfin-vue/i18n", "vite/client", "vue" ]