Created
July 21, 2020 15:18
-
-
Save naishe/4fa54ae675bf7b410a22d7ef7fd26ca7 to your computer and use it in GitHub Desktop.
i18next custom formatting function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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