useTranslation

See source code

Returns a function to translate a message into a string based on the current translation.

Pass a message declared with defineMessages, or a translation key. Messages are ICU MessageFormat, so a message can pluralise or select on the values you pass it. A declared message missing from the catalog falls back to its defaultMessage; an unknown key is returned as-is.

function useTranslation(): (
  message?: Exclude<string, TLUiTranslationKey> | string | TLI18nMessage,
  values?: TLUiTranslationValues,
) => string;

Example

const messages = defineMessages({
  selected: {
    id: "my-app.selected",
    defaultMessage: "{count, plural, one {# shape} other {# shapes}}",
  },
});

const msg = useTranslation();
const label = msg(messages.selected, { count: 5 });
const title = msg("my-app.title");
Prev
useTools
Next
useUiEvents