Skip to content

Instantly share code, notes, and snippets.

@naishe
Created July 21, 2020 15:18
Show Gist options
  • Save naishe/4fa54ae675bf7b410a22d7ef7fd26ca7 to your computer and use it in GitHub Desktop.
Save naishe/4fa54ae675bf7b410a22d7ef7fd26ca7 to your computer and use it in GitHub Desktop.
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