I am currently working on a Photoshop Plugin which loops over all the text inside each textLayer.
I then try to match that text with data from a spreadsheet which contains the same texts. The full functionality is used to be able to easily loop over text layers and translate them into different markets as the spreadsheet contains data for multiple languages.
So what im firstly interested in, is to compare the english text on the text layers with the english text row in the spreadsheet, to be able to determine if I have any translations for that specific text.
I am using localCompare you match th two different texts.
Currently when I using the following condition to determine if the texts matches.
if (textLayer.localeCompare(translationText, 'en', { sensitivity: 'base' }) === 0) {
console.log(textLayer + translationText[l][0] + ' %c !Matches! ', 'background: #222; color: #bada55');
}
In my console I get the following results:
The Gift EditThe Gift Edit !Matches!
We got just the right styles for you.We got just the right styles for you. !Matches!
Which is also what I would expect, but as soon as I have texts which contain single quotes, I dont get any match as in the example below:
Haven't bought this year's gifts yet? Do not worry. Haven't bought this year's gifts yet? Do not worry.
I tried playing around with the sensitivity of the localCompare but I am unable to figure what the right setup would be. Does anyone know how this can be achieved. Let me know if I need to clarify more.
!EDIT! By request in the comments I have tried to make a more clear example and by doing so I think I figured out what the error is. And it seems to be that one of the texts includes a breakline and the other one does not. See this codepen as an example:
https://codepen.io/fennefoss/pen/BaMpeaO?editors=1111
If you remove the breakline in variable 'a' the texts are matched. How can I do a comapre of two texts which ignores breaklines?
I ended up fixing the issue with the breakline in the text by using a RegEx to remove breaklines before comparing the strings. The console was not displaying the breaklines when logging the text which was a bit misleading, and something to be aware of for the future.
let sanitizedTextItem = str.replace(/(?:\r\n|\r|\n)/g, '');