Created
August 6, 2020 19:37
-
-
Save anthumchris/7096852f7b0b750243320f11c9fd8ae3 to your computer and use it in GitHub Desktop.
i18n Pattern
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
// 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 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
// 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' | |
} |
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
// 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