Created
January 3, 2020 10:41
-
-
Save jacob-jonkman/81b303c964ee3f0883b95c43d54b68d4 to your computer and use it in GitHub Desktop.
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
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