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 i18n translation addition #9451

Merged
merged 5 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export default defineComponent({
},
parentTypes: {
type: Array as PropType<string[]>,
default: () => [],
},
credentialData: {},
credentialId: {
Expand Down Expand Up @@ -274,21 +275,21 @@ export default defineComponent({
return '';
}

const appName = getAppNameFromCredType((this.credentialType as ICredentialType).displayName);
const appName = getAppNameFromCredType(this.credentialType.displayName);

return (
appName ||
this.$locale.baseText('credentialEdit.credentialConfig.theServiceYouReConnectingTo')
);
},
credentialTypeName(): string {
return (this.credentialType as ICredentialType)?.name;
return this.credentialType?.name;
},
credentialOwnerName(): string {
return this.credentialsStore.getCredentialOwnerNameById(`${this.credentialId}`);
},
documentationUrl(): string {
const type = this.credentialType as ICredentialType;
const type = this.credentialType;
const activeNode = this.ndvStore.activeNode;
const isCommunityNode = activeNode ? isCommunityPackageName(activeNode.type) : false;

Expand Down
59 changes: 15 additions & 44 deletions packages/editor-ui/src/plugins/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 @@ -437,9 +436,7 @@ async function setLanguage(language: string) {
return language;
}

export async function loadLanguage(language?: string) {
if (!language) return;

export async function loadLanguage(language: string) {
if (i18nInstance.global.locale === language) {
return await setLanguage(language);
}
Expand All @@ -466,64 +463,38 @@ export async function loadLanguage(language?: string) {
*/
export function addNodeTranslation(
nodeTranslation: { [nodeType: string]: object },
language: keyof I18nOptions['messages'],
language: string,
) {
const oldNodesBase: { nodes: {} } = i18nInstance.global.messages[language]['n8n-nodes-base'] ?? {
nodes: {},
};

const updatedNodes = {
...oldNodesBase.nodes,
...nodeTranslation,
};

const newNodesBase = {
'n8n-nodes-base': Object.assign(oldNodesBase, { nodes: updatedNodes }),
const newMessages = {
'n8n-nodes-base': {
nodes: nodeTranslation,
},
};

i18nInstance.global.setLocaleMessage(
language,
Object.assign(i18nInstance.global.messages[language], newNodesBase),
);
i18nInstance.global.mergeLocaleMessage(language, newMessages);
}

/**
* Add a credential translation to the i18n instance's `messages` object.
*/
export function addCredentialTranslation(
nodeCredentialTranslation: { [credentialType: string]: object },
language: keyof I18nOptions['messages'],
language: string,
) {
const oldNodesBase: { credentials: {} } = i18nInstance.global.messages[language][
'n8n-nodes-base'
] || { credentials: {} };

const updatedCredentials = {
...oldNodesBase.credentials,
...nodeCredentialTranslation,
};

const newNodesBase = {
'n8n-nodes-base': Object.assign(oldNodesBase, { credentials: updatedCredentials }),
const newMessages = {
'n8n-nodes-base': {
credentials: nodeCredentialTranslation,
},
};

i18nInstance.global.setLocaleMessage(
language,
Object.assign(i18nInstance.global.messages[language], newNodesBase),
);
i18nInstance.global.mergeLocaleMessage(language, newMessages);
}

/**
* Add a node's header strings to the i18n instance's `messages` object.
*/
export function addHeaders(
headers: INodeTranslationHeaders,
language: keyof I18nOptions['messages'],
) {
i18nInstance.global.setLocaleMessage(
language,
Object.assign(i18nInstance.global.messages[language], { headers }),
);
export function addHeaders(headers: INodeTranslationHeaders, language: string) {
i18nInstance.global.mergeLocaleMessage(language, { headers });
}

export const i18n: I18nClass = new I18nClass();
Expand Down
Loading