Skip to content

Instantly share code, notes, and snippets.

@anthumchris
Created August 6, 2020 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthumchris/7096852f7b0b750243320f11c9fd8ae3 to your computer and use it in GitHub Desktop.
Save anthumchris/7096852f7b0b750243320f11c9fd8ae3 to your computer and use it in GitHub Desktop.
i18n Pattern
// Devs can easily use English strings that will be translated if necessary
function DeleteButton() {
function prompt() {
alert(intl('Are you sure you want to delete gateway?'))
}
return(
<button onclick={prompt}>
{intl('Delete Gateway')}
</button>
)
}
function intl(s) {
// get hash key from keys.js
const keys = ...
const key = keys[s]
// determine which locale-*.js file to use
const locale = ...
return locale[key]
}
// this is automatically built from scanning code. English is main language. Unique hash IDs could be created
{
'Are you sure you want to delete gateway?': 'af2s2c',
'Delete Gateway': '2c2a98'
}
// translation teams would use software to know when new keys are needed/added and provide values
{
'af2s2c': 'Está seguro que que borrar el gateway?'
'2c2a98' : 'Borrar Gateway'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment