Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double-escaping of newlines #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions lib/compiler_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ function to_c(locale) {
return locale.toLowerCase().replace(/-/g, '_');
}

// escape C string to write all in one line.
function esc(str) {
// TODO: simple & dirty, should be improved.
return JSON.stringify(str).slice(1, -1);
}

const pf_enum = {
zero: 'LV_I18N_PLURAL_TYPE_ZERO',
one: 'LV_I18N_PLURAL_TYPE_ONE',
Expand Down Expand Up @@ -49,7 +43,7 @@ function lang_plural_template(l, form, data) {
const loc = to_c(l);
return `
static const lv_i18n_phrase_t ${loc}_plurals_${form}[] = {
${Object.entries(data[l].plural[form]).map(([ k, val ]) => ` {"${esc(k)}", "${esc(val)}"},`).join('\n')}
${Object.entries(data[l].plural[form]).map(([ k, val ]) => ` {"${k}", "${val}"},`).join('\n')}
{NULL, NULL} // End mark
};
`.trim();
Expand All @@ -59,7 +53,7 @@ function lang_singular_template(l, data) {
const loc = to_c(l);
return `
static const lv_i18n_phrase_t ${loc}_singulars[] = {
${Object.entries(data[l].singular).map(([ k, val ]) => ` {"${esc(k)}", "${esc(val)}"},`).join('\n')}
${Object.entries(data[l].singular).map(([ k, val ]) => ` {"${k}", "${val}"},`).join('\n')}
{NULL, NULL} // End mark
};
`.trim();
Expand Down