bunkat/pseudoloc

Space is a bad padding for extend

Opened this issue · 3 comments

@bunkat This is still one of the best, tiny pseudo localization libraries. I love it and use it extensively in all projects. Are you still maintaining this?

I really would like to improve the extend option... extending with spaces is normally not useful since HTML considers 10 spaces and 1 space as a single space. So really the extend option does not have any effect.

I recommend the following change in pad:

const paddingString = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Amet consectetur adipiscing elit ut aliquam purus. Amet risus nullam eget felis eget nunc lobortis mattis aliquam. Felis eget nunc lobortis mattis aliquam. Sem integer vitae justo eget magna. Mi eget mauris pharetra et ultrices neque ornare aenean. Sit amet mattis vulputate enim nulla aliquet porttitor lacus. Nisi est sit amet facilisis magna etiam. Dolor sit amet consectetur adipiscing elit duis. Sed vulputate mi sit amet mauris commodo quis imperdiet massa. Massa tempor nec feugiat nisl pretium fusce id velit ut. At urna condimentum mattis pellentesque id. Vel orci porta non pulvinar neque.';
var length = Math.floor((str.length * percent) / 2),
  leftPad = '',
  rightPad = '';
if (length > paddingString.length) {
  leftPad = paddingStr;
  rightPad = paddingStr;
} else {
  leftPad = paddingString.substr(0, length);
  rightPad = paddingString.substr(paddingString.length - length, length);
}
return leftPad + str + rightPad;

@jacalata Your fork seem to have solved this issue... But one problem I have with that is it does not add spaces. Should we assume this project is abandoned?

I do believe this project is abandoned, yes. I'm happy to take contributions to my fork - I'm afraid I don't understand what your problem is with mine? Sorry for the slow response - I thought I'd look into your comment more when I had time, and never got around to it so here is the quick answer I should have given immediately :)