Last active
July 31, 2019 16:46
-
-
Save fxg42/a2fec2a8803164d44f5de18353a18a4f to your computer and use it in GitHub Desktop.
Create key from UTF-8 string
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 { asKey } = require('./utils'); | |
const text = { | |
"520407a476092ac19c671e1e75d052bd": "i18n!", | |
}; | |
const gettext = (str) => text[asKey(str)] || str | |
console.log(gettext("Iлtèrnåtïonɑlíƶatï߀ԉ")); //=> "i18n!" | |
console.log(gettext("Autre chose!")); //=> "Autre chose!" |
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 diacritics = require('diacritics'); | |
const crypto = require('crypto'); | |
const asKey = (str) => crypto.createHash('md5').update(diacritics.remove(str)).digest('hex'); | |
module.exports = { asKey }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment