From a957d7d5647dc9a9470bf93aab376d8b59f24d4f Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Tue, 3 Dec 2024 13:26:14 +0100 Subject: [PATCH] Add method to translate the headers from (German/Dutch into English) while the CSV data is being parsed --- .../src/importers/passwordxp-csv-importer.ts | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/libs/importer/src/importers/passwordxp-csv-importer.ts b/libs/importer/src/importers/passwordxp-csv-importer.ts index 461432e98d..9d17f671b6 100644 --- a/libs/importer/src/importers/passwordxp-csv-importer.ts +++ b/libs/importer/src/importers/passwordxp-csv-importer.ts @@ -8,6 +8,35 @@ import { Importer } from "./importer"; const _mappedColumns = new Set(["Title", "Username", "URL", "Password", "Description"]); +/* Translates the headers from non-English to English + * This is necessary because the parser only maps English headers to ciphers + * Currently only supports German and Dutch translations + */ +function translateIntoEnglishHeaders(header: string): string { + const translations: { [key: string]: string } = { + Titel: "Title", + // The header column 'User name' is parsed by the parser, but cannot be used as a variable. This converts it to a valid variable name, prior to parsing. + "User name": "Username", + Benutzername: "Username", + Gebruikersnaam: "Username", + Konto: "Account", + Passwort: "Password", + Wachtwoord: "Password", + "Geändert am": "Modified", + Gewijzigd: "Modified", + "Erstellt am": "Created", + Gemaakt: "Created", + "Läuft ab am": "Expire on", + "Verloopt op": "Expire on", + Beschreibung: "Description", + Beschrijving: "Description", + "Geändert von": "Modified by", + "Gewijzigd door": "Modified by", + }; + + return translations[header] || header; +} + /** * PasswordXP CSV importer */ @@ -17,11 +46,11 @@ export class PasswordXPCsvImporter extends BaseImporter implements Importer { * @param data */ parse(data: string): Promise { - // The header column 'User name' is parsed by the parser, but cannot be used as a variable. This converts it to a valid variable name, prior to parsing. - data = data.replace(";User name;", ";Username;"); - const result = new ImportResult(); - const results = this.parseCsv(data, true, { skipEmptyLines: true }); + const results = this.parseCsv(data, true, { + skipEmptyLines: true, + transformHeader: translateIntoEnglishHeaders, + }); if (results == null) { result.success = false; return Promise.resolve(result);