Skip to content

Instantly share code, notes, and snippets.

@jacob-jonkman
Created January 3, 2020 10:41
Show Gist options
  • Save jacob-jonkman/81b303c964ee3f0883b95c43d54b68d4 to your computer and use it in GitHub Desktop.
Save jacob-jonkman/81b303c964ee3f0883b95c43d54b68d4 to your computer and use it in GitHub Desktop.
function constructTranslationsForLanguage(lang, translations): Promise<any> {
return request(listTermsOptions)
.then(body => JSON.parse(body).result.terms)
.then(terms => {
for (const index in terms) {
if (terms.hasOwnProperty(index)) {
const term = encodeAsFirebaseKey(terms[index]['term']);
if (!translations[term]) {
translations[term] = {};
}
translations[term][lang] = terms[index]['translation']['content'];
}
}
return translations;
})
}
function encodeAsFirebaseKey(string: string): string {
return string.replace(/%/g, '%25')
.replace(/\./g, '%2E')
.replace(/#/g, '%23')
.replace(/\$/g, '%24')
.replace(/\//g, '%2F')
.replace(/\[/g, '%5B')
.replace(/]/g, '%5D');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment