New line feed in localazy string

I have created a key on localazy portal with value containing text “\n”. Mentioning below key & value:
key - login_text_key
Value - Login is happening.\nThis may take up to 1 minute."

Upon syncing with localazy server received a value with extra slash
key - login_text_key
Value - Login is happening.\\nThis may take up to 1 minute."

Note:
I need to use “\n” instead of adding “Enter”

1 Like

Hello,

the translation process on Localazy is designed for translators whenever possible, so placing \n in the translation field should be encoded correctly as \n since translators are typically not trying to place escaped characters.

If you really want to introduce a new line, just use Enter, which should be correctly encoded based on the output format (e.g., as \n for JSON etc.).

What is your file format, and why do you need \n instead of a different representation?

We are aware that \n instead of a new line is required for Android to work correctly with Preference screens and fragments. Is it your case?

Hi @vaclav ,

I have the same issue. I would need to use \n for a new line on Android platform.
Localazy version: Localazy CLI, v1.7.8
localazy.json file:

{
  "conversion": {
    "actions": [
      {
        "conditions": [
          "!~equals: ${lang}, en"
        ],
        "type": "android",
        "output": "presentation/src/main/res/values-${lang}/strings.xml",
        "excludeKeys": [
          "SUFFIX-CI:_ios"
        ],
        "replacements": {
          "<": "&lt;",
          ">": "&gt;"
        }
      },
      {
        "conditions": [
          "equals: ${lang}, en"
        ],
        "type": "android",
        "output": "presentation/src/main/res/values/strings.xml",
        "excludeKeys": [
          "SUFFIX-CI:_ios"
        ],
        "replacements": {
          "<": "&lt;",
          ">": "&gt;"
        }
      }
    ]
  }
}

Enter is not encoded as \n, when I used "type": "android",. Do you have any suggestion how to use \n on Android?
Thanks in advance for trying to help me solve this problem.

Hello, while our format with empty lines is the same as using \n since both ways are fully supported by Android, you can enable using \n by adding “features”: [“escape_new_lines”] to the upload section.

It’s described here:

Oh, sorry. I just noticed that your particular case is related to conversions where this is not yet supported. I’m adding it to our list.

When do you plan to release a version with this support? @vaclav

We have added the feature ;-).


  "conversion": {
    "actions": {
      "type": "android",
      "output": "${lang}.xml",
      "params": {
        "escape_new_lines": "yes"
      }
    }
  }

The magic is “escape_new_lines”: “yes”.

Thanks @vaclav, it works!

Did you manage to solve the problem? I encountered the same problem.