Skip to content

Instantly share code, notes, and snippets.

@fxg42
Last active July 31, 2019 16:46
Show Gist options
  • Save fxg42/a2fec2a8803164d44f5de18353a18a4f to your computer and use it in GitHub Desktop.
Save fxg42/a2fec2a8803164d44f5de18353a18a4f to your computer and use it in GitHub Desktop.
Create key from UTF-8 string
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!"
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