From 48757718e854bdd4a84b39bc9ba7be4e36ef7514 Mon Sep 17 00:00:00 2001 From: Aviv Carmi Date: Mon, 4 Jan 2021 20:16:20 +0200 Subject: [PATCH] fix alphabet translation using hash function and prefix --- src/localization.js | 16 +++++++++++----- src/localization_settings.js | 29 ----------------------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/localization.js b/src/localization.js index 309a6fc..864fc6d 100644 --- a/src/localization.js +++ b/src/localization.js @@ -16,11 +16,7 @@ export function translateIdentifier(identifier) { } export function translateIdentifierAlphabetically(identifier) { - let result = "" - for (const char of identifier) { - result += localizationSettings.chars[char] || char - } - return result + return `chavascript_${simpleHash(identifier)}`; } export function isQuote(charCode) { @@ -48,3 +44,13 @@ function reverseObject(obj) { } return result } + +function simpleHash(str) { + let hash = 0, i, chr; + for (i = 0; i < str.length; i++) { + chr = str.charCodeAt(i); + hash = ((hash << 5) - hash) + chr; + hash |= 0; + } + return hash; +} diff --git a/src/localization_settings.js b/src/localization_settings.js index 99bc0d2..a2ea42a 100644 --- a/src/localization_settings.js +++ b/src/localization_settings.js @@ -218,35 +218,6 @@ function flattenObject(obj) { export default { keywords: flattenObject(classifiedKeywords), dictionary: flattenObject(classifiedDictionary), - chars: { - "א": "a", - "ב": "b", - "ג": "g", - "ד": "d", - "ה": "h", - "ו": "v", - "ז": "z", - "ח": "h", - "ט": "t", - "י": "i", - "כ": "k", - "ל": "l", - "מ": "m", - "נ": "n", - "ס": "s", - "ע": "a", - "פ": "p", - "צ": "z", - "ק": "k", - "ר": "r", - "ש": "sh", - "ת": "t", - "ן": "n", - "ם": "m", - "ך": "ch", - "ף": "f", - "ץ": "z" - }, quotes: [ '"', "'",