Skip to content
Discussion options

You must be logged in to vote

Finally invented a pure JS reusable translation function ts() (translate string):

import { i18n } from '@lingui/core'
import { generateMessageId } from '@lingui/message-utils/generateMessageId'

/**
 * Translates a variable string using Lingui.
 *
 * This function generates a message ID from the input string and context,
 * then translates it using the Lingui i18n instance. If no translation is found
 * (indicated by a 6-character alphanumeric result), it returns the original string
 * as a fallback and logs a warning.
 *
 * @param str - The message string to translate
 * @param values - Optional values for interpolation (same as i18n.t)
 * @param options - Optional translation options, i…

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@MurzNN
Comment options

@MurzNN
Comment options

@timofei-iatsenko
Comment options

@MurzNN
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@MurzNN
Comment options

@MurzNN
Comment options

@MurzNN
Comment options

Answer selected by MurzNN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants