Skip to content

Return static default value when localization key does not exist #23

Answered by claviska
pchaudha asked this question in Q&A
Discussion options

You must be logged in to vote

If a term doesn't exist in the target translation or the fallback, the key will be output. There's currently no way to change this, but there's an undocumented method to check if a term exists that may help you.

localize/src/index.ts

Lines 131 to 149 in 6e9dfa5

/** Determines if the specified term exists, optionally checking the fallback translation. */
exists<K extends keyof UserTranslation>(key: K, options: Partial<ExistsOptions>): boolean {
const { primary, secondary } = this.getTranslationData(options.lang ?? this.lang());
options = {
includeFallback: false,
...options
};
if (
(primary && primary[key]) ||
(secondary && s…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pchaudha
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