totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

CSV translation problem with special characters #700

Closed fgnm closed 5 years ago

fgnm commented 5 years ago

Hi! I've noticed a bug with CSV translation parser script. In some of my strings I must include some HTML special characters, for example the &, well the parser recognize the ; as delimiter, so parsing is compromised.

Also I would understand the reason of the replace() in this line: https://github.com/totaljs/framework/blob/master/bin/totaljs#L768, why it duplicates "?

I'm writing a manager for collaborative translations, thank you.

petersirka commented 5 years ago

Can you send me some view? I need to test it.

petersirka commented 5 years ago

BTW why quotes are duplicated? Read here: https://stackoverflow.com/questions/17808511/properly-escape-a-double-quote-in-csv

fgnm commented 5 years ago

For example:

<div>
@(I love Total.js; It's a very good framework)
</div>

With the command totaljs --translatecsv I got something like:

Hash;Text;Translation
T-14328244;"I love Total.js; It's a very good framework";

Then run totaljs -csv translate.csv:

// Total.js resource file
// Created: 2019-02-20 15:42

T-14328244           : It's a very good framework

And it's wrong. So, I've edit your script to replace each ; into \;, similar to double quote escape, and modified line.split(';') into line.split(/(?<!\\);/g) in your parse_csv(content) function.

There will certainly be more smart solutions :see_no_evil:

petersirka commented 5 years ago

Yes, I will need to rewrite CSV parser... Shit.

petersirka commented 5 years ago

Hi, I have added csv parser. Try it: $ npm install -g total.js@beta.