Last active
September 9, 2021 15:55
-
-
Save xiCO2k/219e34681cdad4a498867715de47bf34 to your computer and use it in GitHub Desktop.
vue-i18n CustomFormatter using the laravel replacement logic
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
// const i18n = new VueI18n({ | |
// formatter: new CustomFormatter(), | |
// }); | |
export default class CustomFormatter { | |
interpolate (message, values) { | |
const capitalize = s => s.charAt(0).toUpperCase() + s.slice(1); | |
Object.entries(values || []).forEach(([key, value]) => { | |
value = '' + value; | |
message = message | |
.replace(`:${key}`, value) | |
.replace(`:${key.toUpperCase()}`, value.toUpperCase()) | |
.replace(`:${capitalize(key)}`, capitalize(value)); | |
}); | |
return [message]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment