Skip to content

i18next escapes HTML special characters in substitutions by default #43

@Finesse

Description

@Finesse

This is not a problem in angular-i18next. But I think you can improve the usage experience by considering this i18next feature in any way. It is a problem because Angular escapes special characters too which leads to double-escaping. For example, this code {{ 'greeting' | i18next: { name: '"Google"' } }} gives this string in browser Hello, "Google"!. You can mention this feature in the readme and offer/implement one of the solutions:

  • Disable the escaping globally in the i18next configuration:

    i18next.init({
      // ...,
      interpolation: {
        escapeValue: false,
      },
    });

    This is the best solution IMHO because dealing with a raw HTML in Angular is a rare case and one who deals with raw HTML would need to escape the substitutions manually anyway.

  • Disable the escaping in the pipe or/and in the service:

    i18next.t(key, {
      ...substitutions,
      interpolation: {
        escapeValue: false,
        ...substitutions.interpolation,
      },
    })
  • Disable the escaping in templates: greeting: 'Hello, {{- name}}!'

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions