From cdb88ff941076bd5f85393c50b4893f995a8e8fa Mon Sep 17 00:00:00 2001 From: Manuel Date: Sat, 5 Aug 2023 21:36:15 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20type=20safety=20for=20t?= =?UTF-8?q?ranslations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/i18n.d.ts | 127 ------------------ src/tools/server/getServerSideTranslations.ts | 3 +- src/tools/server/translation-namespaces.ts | 12 +- src/widgets/dashDot/DashDotGraph.tsx | 6 +- src/widgets/weather/WeatherIcon.tsx | 5 +- yarn.lock | 18 +-- 7 files changed, 18 insertions(+), 155 deletions(-) delete mode 100644 src/i18n.d.ts diff --git a/package.json b/package.json index 98065dfdd..f78f6da75 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "js-file-download": "^0.4.12", "next": "13.4.10", "next-auth": "^4.22.3", - "next-i18next": "^13.0.0", + "next-i18next": "^14.0.0", "nzbget-api": "^0.0.3", "prisma": "^5.0.0", "prismjs": "^1.29.0", diff --git a/src/i18n.d.ts b/src/i18n.d.ts deleted file mode 100644 index 009d77c91..000000000 --- a/src/i18n.d.ts +++ /dev/null @@ -1,127 +0,0 @@ -import 'i18next'; - -import authInvite from '../public/locales/en/authentication/invite.json'; -import authLogin from '../public/locales/en/authentication/login.json'; -import boardsManage from '../public/locales/en/boards/manage.json'; -import boardsCommon from '../public/locales/en/boards/common.json'; -import boardsCustomize from '../public/locales/en/boards/customize.json'; -import common from '../public/locales/en/common.json'; -import layout from '../public/locales/en/layout/common.json'; -import layoutElementSelector from '../public/locales/en/layout/element-selector/selector.json'; -import layoutHeader from '../public/locales/en/layout/header.json'; -import layoutToggleEditMode from '../public/locales/en/layout/header/actions/toggle-edit-mode.json'; -import layoutMobileDrawer from '../public/locales/en/layout/mobile/drawer.json'; -import layoutModalAbout from '../public/locales/en/layout/modals/about.json'; -import layoutModalAddApp from '../public/locales/en/layout/modals/add-app.json'; -import layoutModalChangePosition from '../public/locales/en/layout/modals/change-position.json'; -import moduleBookmark from '../public/locales/en/modules/bookmark.json'; -import moduleCalendar from '../public/locales/en/modules/calendar.json'; -import moduleMediaCards from '../public/locales/en/modules/common-media-cards.json'; -import moduleCommon from '../public/locales/en/modules/common.json'; -import moduleDashDot from '../public/locales/en/modules/dashdot.json'; -import moduleDate from '../public/locales/en/modules/date.json'; -import moduleDownload from '../public/locales/en/modules/dlspeed.json'; -import moduleDnsHoleControls from '../public/locales/en/modules/dns-hole-controls.json'; -import moduleDnsHoleSummary from '../public/locales/en/modules/dns-hole-summary.json'; -import moduleDocker from '../public/locales/en/modules/docker.json'; -import moduleIframe from '../public/locales/en/modules/iframe.json'; -import moduleMediaRequests from '../public/locales/en/modules/media-requests-list.json'; -import moduleMediaRequestsStats from '../public/locales/en/modules/media-requests-stats.json'; -import moduleMediaServer from '../public/locales/en/modules/media-server.json'; -import moduleOverseerr from '../public/locales/en/modules/overseerr.json'; -import modulePing from '../public/locales/en/modules/ping.json'; -import moduleRss from '../public/locales/en/modules/rss.json'; -import moduleSearch from '../public/locales/en/modules/search.json'; -import moduleTorrentStatus from '../public/locales/en/modules/torrents-status.json'; -import moduleUsenet from '../public/locales/en/modules/usenet.json'; -import moduleVideoStream from '../public/locales/en/modules/video-stream.json'; -import moduleWeather from '../public/locales/en/modules/weather.json'; -import settingsCommon from '../public/locales/en/settings/common.json'; -import settingsAppWidth from '../public/locales/en/settings/customization/app-width.json'; -import settingsColorSelector from '../public/locales/en/settings/customization/color-selector.json'; -import settingsGeneral from '../public/locales/en/settings/customization/general.json'; -import settingsGridstack from '../public/locales/en/settings/customization/gridstack.json'; -import settingsOpacitySelector from '../public/locales/en/settings/customization/opacity-selector.json'; -import settingsPageAppearance from '../public/locales/en/settings/customization/page-appearance.json'; -import settingsShadeSelector from '../public/locales/en/settings/customization/shade-selector.json'; -import settingsColorSchema from '../public/locales/en/settings/general/color-schema.json'; -import settingsConfigChanger from '../public/locales/en/settings/general/config-changer.json'; -import settingsInternationalization from '../public/locales/en/settings/general/internationalization.json'; -import settingsSearchEngine from '../public/locales/en/settings/general/search-engine.json'; -import settingsThemeSelector from '../public/locales/en/settings/general/theme-selector.json'; -import settingsWidgetPositions from '../public/locales/en/settings/general/widget-positions.json'; -import userPreferences from '../public/locales/en/user/preferences.json'; -import widgetsDraggableList from '../public/locales/en/widgets/draggable-list.json'; -import widgetsErrorBoundary from '../public/locales/en/widgets/error-boundary.json'; -import widgetsLocation from '../public/locales/en/widgets/location.json'; -import zod from '../public/locales/en/zod.json'; - -declare module 'i18next' { - // Extend CustomTypeOptions - interface CustomTypeOptions { - // custom namespace type, if you changed it - defaultNS: 'ns1'; - // custom resources type - resources: { - common: typeof common; - zod: typeof zod; - 'authentication/invite': typeof authInvite; - 'authentication/login': typeof authLogin; - 'boards/common': typeof boardsCommon; - 'boards/manage': typeof boardsManage; - 'boards/customize': typeof boardsCustomize; - 'layout/common': typeof layout; - 'layout/element-selector/selector': typeof layoutElementSelector; - 'layout/header': typeof layoutHeader; - 'layout/header/actions/toggle-edit-mode': typeof layoutToggleEditMode; - 'layout/mobile/drawer': typeof layoutMobileDrawer; - 'layout/modals/about': typeof layoutModalAbout; - 'layout/modals/add-app': typeof layoutModalAddApp; - 'layout/modals/change-position': typeof layoutModalChangePosition; - 'modules/bookmark': typeof moduleBookmark; - 'modules/calendar': typeof moduleCalendar; - 'modules/common-media-cards': typeof moduleMediaCards; - 'modules/common': typeof moduleCommon; - 'modules/dashdot': typeof moduleDashDot; - 'modules/date': typeof moduleDate; - 'modules/dlspeed': typeof moduleDownload; - 'modules/dns-hole-controls': typeof moduleDnsHoleControls; - 'modules/dns-hole-summary': typeof moduleDnsHoleSummary; - 'modules/docker': typeof moduleDocker; - 'modules/iframe': typeof moduleIframe; - 'modules/media-requests-list': typeof moduleMediaRequests; - 'modules/media-requests-stats': typeof moduleMediaRequestsStats; - 'modules/media-server': typeof moduleMediaServer; - 'modules/overseerr': typeof moduleOverseerr; - 'modules/ping': typeof modulePing; - 'modules/rss': typeof moduleRss; - 'modules/search': typeof moduleSearch; - 'modules/torrents-status': typeof moduleTorrentStatus; - 'modules/usenet': typeof moduleUsenet; - 'modules/video-stream': typeof moduleVideoStream; - 'modules/weather': typeof moduleWeather; - 'settings/common': typeof settingsCommon; - 'settings/customization/app-width': typeof settingsAppWidth; - 'settings/customization/color-selector': typeof settingsColorSelector; - 'settings/customization/general': typeof settingsGeneral; - 'settings/customization/gridstack': typeof settingsGridstack; - 'settings/customization/opacity-selector': typeof settingsOpacitySelector; - 'settings/customization/page-appearance': typeof settingsPageAppearance; - 'settings/customization/shade-selector': typeof settingsShadeSelector; - 'settings/general/color-schema': typeof settingsColorSchema; - 'settings/general/config-changer': typeof settingsConfigChanger; - 'settings/general/internationalization': typeof settingsInternationalization; - 'settings/general/search-engine': typeof settingsSearchEngine; - 'settings/general/theme-selector': typeof settingsThemeSelector; - 'settings/general/widget-positions': typeof settingsWidgetPositions; - 'user/preferences': typeof userPreferences; - 'widgets/draggable-list': typeof widgetsDraggableList; - 'widgets/error-boundary': typeof widgetsErrorBoundary; - 'widgets/location': typeof widgetsLocation; - }; - // other - } -} - -import { CustomTypeOptions } from 'i18next'; -export type TranslationNamespace = keyof CustomTypeOptions['resources']; \ No newline at end of file diff --git a/src/tools/server/getServerSideTranslations.ts b/src/tools/server/getServerSideTranslations.ts index 4242b357f..6302933aa 100644 --- a/src/tools/server/getServerSideTranslations.ts +++ b/src/tools/server/getServerSideTranslations.ts @@ -3,10 +3,9 @@ import { IncomingMessage, ServerResponse } from 'http'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { COOKIE_LOCALE_KEY } from '../../../data/constants'; -import { TranslationNamespace } from '~/i18n'; export const getServerSideTranslations = async ( - namespaces: TranslationNamespace[], + namespaces: string[], requestLocale?: string, req?: IncomingMessage, res?: ServerResponse diff --git a/src/tools/server/translation-namespaces.ts b/src/tools/server/translation-namespaces.ts index 5cc9737c4..3e8e14ba5 100644 --- a/src/tools/server/translation-namespaces.ts +++ b/src/tools/server/translation-namespaces.ts @@ -1,6 +1,4 @@ -import { TranslationNamespace } from '~/i18n'; - -export const boardNamespaces: TranslationNamespace[] = [ +export const boardNamespaces = [ 'common', 'zod', 'layout/element-selector/selector', @@ -43,14 +41,14 @@ export const boardNamespaces: TranslationNamespace[] = [ 'boards/common', ]; -export const manageNamespaces: TranslationNamespace[] = [ +export const manageNamespaces = [ 'user/preferences', 'boards/manage', 'zod', ]; -export const loginNamespaces: TranslationNamespace[] = ['authentication/login', 'zod']; +export const loginNamespaces = ['authentication/login', 'zod']; -export const inviteNamespaces: TranslationNamespace[] = ['authentication/invite', 'zod']; +export const inviteNamespaces = ['authentication/invite', 'zod']; -export const onboardNamespaces: TranslationNamespace[] = ['common', 'zod']; +export const onboardNamespaces = ['common', 'zod']; diff --git a/src/widgets/dashDot/DashDotGraph.tsx b/src/widgets/dashDot/DashDotGraph.tsx index 21c5dbc45..28d7d2382 100644 --- a/src/widgets/dashDot/DashDotGraph.tsx +++ b/src/widgets/dashDot/DashDotGraph.tsx @@ -4,12 +4,8 @@ import { useTranslation } from 'next-i18next'; import { DashDotCompactNetwork, DashDotInfo } from './DashDotCompactNetwork'; import { DashDotCompactStorage } from './DashDotCompactStorage'; -import { CustomTypeOptions } from 'i18next'; - -type GraphType = keyof CustomTypeOptions['resources']['modules/dashdot']['card']['graphs']; - interface DashDotGraphProps { - graph: GraphType; + graph: string; graphHeight: number; isCompact: boolean; multiView: boolean; diff --git a/src/widgets/weather/WeatherIcon.tsx b/src/widgets/weather/WeatherIcon.tsx index e92f6d90f..23325126e 100644 --- a/src/widgets/weather/WeatherIcon.tsx +++ b/src/widgets/weather/WeatherIcon.tsx @@ -11,7 +11,6 @@ import { IconSun, } from '@tabler/icons-react'; import { useTranslation } from 'next-i18next'; -import { TranslationNamespace } from '~/i18n'; import { CustomTypeOptions } from 'i18next'; interface WeatherIconProps { @@ -38,9 +37,7 @@ export const WeatherIcon = ({ code }: WeatherIconProps) => { ); }; - -type WeatherDescription = keyof CustomTypeOptions['resources']['modules/weather']['card']['weatherDescriptions']; -type WeatherDefinitionType = { icon: Icon; name: WeatherDescription; codes: number[] }; +type WeatherDefinitionType = { icon: Icon; name: string; codes: number[] }; // 0 Clear sky // 1, 2, 3 Mainly clear, partly cloudy, and overcast diff --git a/yarn.lock b/yarn.lock index a0793c04b..30e2f360c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5909,7 +5909,7 @@ __metadata: js-file-download: ^0.4.12 next: 13.4.10 next-auth: ^4.22.3 - next-i18next: ^13.0.0 + next-i18next: ^14.0.0 node-mocks-http: ^1.12.2 nzbget-api: ^0.0.3 prettier: ^3.0.0 @@ -6083,7 +6083,7 @@ __metadata: languageName: node linkType: hard -"i18next-fs-backend@npm:^2.1.1": +"i18next-fs-backend@npm:^2.1.5": version: 2.1.5 resolution: "i18next-fs-backend@npm:2.1.5" checksum: 4607e879de8195ff0bf11bdb2367f1c45f947160404b64f52be7e438ae27288e0d11a9b53a4bde2d75a77ac7f3255aa531a4381870e278e72f85ead222ffed31 @@ -7402,21 +7402,21 @@ __metadata: languageName: node linkType: hard -"next-i18next@npm:^13.0.0": - version: 13.3.0 - resolution: "next-i18next@npm:13.3.0" +"next-i18next@npm:^14.0.0": + version: 14.0.0 + resolution: "next-i18next@npm:14.0.0" dependencies: "@babel/runtime": ^7.20.13 "@types/hoist-non-react-statics": ^3.3.1 core-js: ^3 hoist-non-react-statics: ^3.3.2 - i18next-fs-backend: ^2.1.1 + i18next-fs-backend: ^2.1.5 peerDependencies: - i18next: ^22.0.6 + i18next: ^23.0.1 next: ">= 12.0.0" react: ">= 17.0.2" - react-i18next: ^12.2.0 - checksum: 4c3aa5bbbc12964ed6f61f37d33f4319abd04932d6871baba9f209183952b286470fff80f90a94ccddba736c8fb13a9238effa1e8247dfb08e2239cbdc4fb769 + react-i18next: ^13.0.0 + checksum: a699f6fdee650a2456c463d59910bf38d9f891d224c00de639b15740e8cbf939a2469c8c733007b4f1c2fe0f85c18d43b6f1e814f2127ef30a0d3a28a354dc1d languageName: node linkType: hard