faberNovel / ad_localize

ADLocalize is a simple way to manage your localization files. Supported wording sources : CSVs and Google Sheets. Localization file generation available for iOS, Android, JSON (i18next), YAML and Java properties
https://rubygems.org/gems/ad_localize
MIT License
24 stars 8 forks source link

Unneeded newline escaping for json format #66

Closed felginep closed 3 years ago

felginep commented 3 years ago

For the following key in google doc

shared.error.not_found | Resource not found.\n(code 404)

the result of bundle exec ad_localize -k SHEET_ID -o json -t src/assets/localizables gives me the following output:

{
  "en": {
    "shared": {
      "error": {
        "not_found": "Resource not found.\\n(code 404)",
      }
    },

The newline \n is escaped to \\n but should not be.

felginep commented 3 years ago

In fact this is valid escaping from ruby when parsing csv file. Indeed

> CSV.parse('shared.error.not_found,Resource not found.\n(code 404)')
=> [["shared.error.not_found", "Resource not found.\\n(code 404)"]]

The solution here is to insert a real newline in the spreadsheet

That way the csv escape the newline:

shared.error.not_found,"Resource not found.
(code 404)"

And now:

> CSV.parse('shared.error.not_found,"Resource not found.
(code 404)"')
=> [["shared.error.not_found", "Resource not found.\n(code 404)"]]