diff --git a/index.js b/index.js index c7a2bc5..99e94f2 100644 --- a/index.js +++ b/index.js @@ -208,8 +208,7 @@ TranslationManager.prototype.getSuggestedKey = async function (pathToFile, text, var words = text.trim().split(' ') if (words.length > 4) words = words.slice(0, 3) - - let word = camelCase(words.join(' ').replace(/[^a-zA-Z ]/g, '')) + let word = camelCase(words.join(' ').replace(/[^a-zA-Z ]/g, '').replace(/\s\s+/g, ' ')) if (!word) word = Math.floor(Math.random() * 10000) let proposedKey = await this.getCompatibleKey(`${prefix}.${word}`, usedKeys) diff --git a/test/test-index.js b/test/test-index.js index 176bdbf..4e28e12 100644 --- a/test/test-index.js +++ b/test/test-index.js @@ -68,6 +68,10 @@ test('getSuggestedKey', async function (t) { var key2 = await m.getSuggestedKey(pathToFile2, 'Little text here with a lot of words that hopefully won\'t appear in the key') t.equal(key2, 'header.titlebar.littleTextHere', 'key is correct') + var pathToFile3 = path.join(__dirname, 'data/test-1/src/components/header/Titlebar.vue') + var key3 = await m.getSuggestedKey(pathToFile3, 'One / three') + t.equal(key3, 'header.titlebar.oneThree', 'key is correct') + cleanupTmp() t.end() }) @@ -92,6 +96,9 @@ test('getSuggestedKey with list of used keys', async function (t) { var keyThree = await m.getSuggestedKey(pathToFile, 'Create Group and a lot of text that stays the same Three', ['test.createGroupAnd']) t.equal(keyThree, 'test.createGroupAnd1', 'key is correct') + var keyFour = await m.getSuggestedKey(pathToFile, 'One / three and a lot of text that stays the same', ['test.oneThree']) + t.equal(keyFour, 'test.oneThree1', 'key is correct') + cleanupTmp() t.end() })