Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): Fix type errors in i18n plugin #9441

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions packages/editor-ui/src/plugins/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Plugin } from 'vue';
import axios from 'axios';
import { createI18n } from 'vue-i18n';
import type { I18nOptions } from 'vue-i18n';
import { locale } from 'n8n-design-system';
import type { INodeProperties, INodePropertyCollection, INodePropertyOptions } from 'n8n-workflow';

Expand Down Expand Up @@ -50,7 +51,7 @@ export class I18nClass {
*/
baseText(
key: BaseTextKey,
options?: { adjustToNumber?: number; interpolate?: { [key: string]: string } },
options?: { adjustToNumber?: number; interpolate?: Record<string, string | number> },
): string {
// Create a unique cache key
const cacheKey = `${key}-${JSON.stringify(options)}`;
Expand Down Expand Up @@ -465,12 +466,13 @@ export async function loadLanguage(language?: string) {
*/
export function addNodeTranslation(
nodeTranslation: { [nodeType: string]: object },
language: string,
language: keyof I18nOptions['messages'],
) {
const oldNodesBase = i18nInstance.global.messages[language]['n8n-nodes-base'] || {};
const oldNodesBase: { nodes: {} } = i18nInstance.global.messages[language]['n8n-nodes-base'] ?? {
nodes: {},
};

const updatedNodes = {
// @ts-ignore
...oldNodesBase.nodes,
...nodeTranslation,
};
Expand All @@ -490,12 +492,13 @@ export function addNodeTranslation(
*/
export function addCredentialTranslation(
nodeCredentialTranslation: { [credentialType: string]: object },
language: string,
language: keyof I18nOptions['messages'],
) {
const oldNodesBase = i18nInstance.global.messages[language]['n8n-nodes-base'] || {};
const oldNodesBase: { credentials: {} } = i18nInstance.global.messages[language][
'n8n-nodes-base'
] || { credentials: {} };

const updatedCredentials = {
// @ts-ignore
...oldNodesBase.credentials,
...nodeCredentialTranslation,
};
Expand All @@ -513,7 +516,10 @@ export function addCredentialTranslation(
/**
* Add a node's header strings to the i18n instance's `messages` object.
*/
export function addHeaders(headers: INodeTranslationHeaders, language: string) {
export function addHeaders(
headers: INodeTranslationHeaders,
language: keyof I18nOptions['messages'],
) {
i18nInstance.global.setLocaleMessage(
language,
Object.assign(i18nInstance.global.messages[language], { headers }),
Expand Down
Loading