From 319cef64c233dcfb465cff765c9800de382ad418 Mon Sep 17 00:00:00 2001 From: Richard Allen Date: Mon, 16 Sep 2024 12:23:45 -0500 Subject: [PATCH] fix double-escaping of newlines Fixes https://github.com/lvgl/lv_i18n/issues/66 --- lib/compiler_template.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/compiler_template.js b/lib/compiler_template.js index 854a064..2b1c1dc 100644 --- a/lib/compiler_template.js +++ b/lib/compiler_template.js @@ -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', @@ -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(); @@ -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();