Skip to main content

Translate user generated content

Your UI strings are written in your primary language — but your users write in their language. A comment, a review, a bio: that's user generated content (UGC), and it can arrive in any of the supported languages.

Pass originLanguage to tell i18n-keyless what language the text is written in. Everything else stays the same: the text itself is the key.

import { I18nKeylessText } from "i18n-keyless-react";

function Comment({ comment }) {
return (
<I18nKeylessText originLanguage={comment.lang}>
{comment.text}
</I18nKeylessText>
);
}
import { getTranslation } from "i18n-keyless-react";

const text = getTranslation(comment.text, { originLanguage: comment.lang });

What happens

Say your primary language is en and a user posts "Hola mundo" with originLanguage="es":

  1. The backend translates it once into your primary language ("Hello world"), which becomes the translation key.
  2. The original text is kept verbatim for viewers in the origin language — Spanish readers always see exactly what the author wrote, never an AI rewrite.
  3. Every other supported language is AI-translated from the primary version.
  4. All viewers can look the translation up by the original text — including viewers in your primary language.

When the viewer's language is the origin language, the text renders as-is with no API call at all.

If originLanguage is omitted or equals your primary language, the regular flow applies unchanged.

Tips

  • Use a namespace for UGC — ideally an unpersisted one (e.g. one per discussion), so high-cardinality user content never bloats your users' local storage or your UI-strings bundle.
  • Billing: a never-seen UGC string costs one extra AI call (origin → primary) on top of the regular translation call. Re-posting the same text is free — it's found again through its origin language.
  • originLanguage accepts any supported language code (fr, en, es, de, …).