Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
i18next custom formatting function
interpolation: {
escapeValue: false,
format: function (value: any, format?: string, lng?: string) {
switch (format) {
case 'flags':
if (
typeof value !== 'number' ||
value < 1 ||
!Number.isInteger(value)
) {
return value;
}
if (lng === 'hi') {
return [...Array(value as number)].map((_) => '🇮🇳').join(' ');
} else {
return [...Array(value as number)].map((_) => '🌎').join(' ');
}
default:
return value;
}
},
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment