Skip to content

Allow JSX in translations #21

@Lukasz-pluszczewski

Description

@Lukasz-pluszczewski

Is your feature request related to a problem? Please describe.
When the translation is JSX (see below), it works fine but validation here logs an error as if the translation is missing.

const translations = {
  foo: {
    'en_US': <div>Foo</div>,
    'pl_PL': <div>Fuu</div>,
  },
}

To avoid the warning you can create a variable translation like this:

const translations = {
  foo: () => ({
    'en_US': <div>Foo</div>,
    'pl_PL': <div>Fuu</div>,
  }),
}

Describe the solution you'd like
JSX seems to work fine, so I would suggest allowing JSX translations and:

  • improving the validation to prevent unnecessary console warnings when translation is not a string (e.g. allowing non-string values that are valid react elements using React.isValidElement() function).
  • updating readme with JSX translation examples

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions