Skip to content

Commit

Permalink
fix: add order to i18n links
Browse files Browse the repository at this point in the history
  • Loading branch information
fsdiogo committed Sep 12, 2018
1 parent c13159d commit 357a678
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
12 changes: 6 additions & 6 deletions add-on/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,15 @@
}
},
"page_landingWelcome_renderWelcome_copy_discover": {
"message": "Discover what you <a>can do with Companion</a> and dive into the distributed web with IPFS!",
"message": "Discover what you <0>can do with Companion</0> and dive into the distributed web with IPFS!",
"description": "Ready message copy (page_landingWelcome_renderWelcome_copy_discover)"
},
"page_landingWelcome_installSteps_title": {
"message": "Is your IPFS daemon running?",
"description": "Install steps title (page_landingWelcome_installSteps_title)"
},
"page_landingWelcome_installSteps_copy_install": {
"message": "If you haven't installed IPFS please do so <a>with these instructions</a>.",
"message": "If you haven't installed IPFS please do so <0>with these instructions</0>.",
"description": "Install steps copy (page_landingWelcome_installSteps_copy_install)"
},
"page_landingWelcome_installSteps_copy_run": {
Expand All @@ -490,31 +490,31 @@
"description": "Resources title (page_landingWelcome_renderResources_title_new_ipfs)"
},
"page_landingWelcome_renderResources_copy_new_ipfs": {
"message": "Read the <a>documentation</a> to learn about the basic <a>concepts</a> and working with IPFS.",
"message": "Read the <0>documentation</0> to learn about the basic <1>concepts</1> and working with IPFS.",
"description": "Resources copy (page_landingWelcome_renderResources_copy_new_ipfs)"
},
"page_landingWelcome_renderResources_title_discover": {
"message": "Discover!",
"description": "Resources title (page_landingWelcome_renderResources_title_discover)"
},
"page_landingWelcome_renderResources_copy_discover": {
"message": "Find <a>useful resources</a> for using IPFS and <a>building things</a> on top of it.",
"message": "Find <0>useful resources</0> for using IPFS and <1>building things</1> on top of it.",
"description": "Resources copy (page_landingWelcome_renderResources_copy_discover)"
},
"page_landingWelcome_renderResources_title_got_questions": {
"message": "Got questions?",
"description": "Resources title (page_landingWelcome_renderResources_title_got_questions)"
},
"page_landingWelcome_renderResources_copy_got_questions": {
"message": "Visit the <a>Discussion and Support Forum</a>.",
"message": "Visit the <0>Discussion and Support Forum</0>.",
"description": "Resources copy (page_landingWelcome_renderResources_copy_got_questions)"
},
"page_landingWelcome_renderResources_title_want_to_help": {
"message": "Want to help?",
"description": "Resources title (page_landingWelcome_renderResources_title_want_to_help)"
},
"page_landingWelcome_renderResources_copy_want_to_help": {
"message": "Join the <a>IPFS Community</a>! Contribute with <a>code</a>, <a>documentation</a>, <a>translations</a> or help by <a>supporting other users</a>.",
"message": "Join the <0>IPFS Community</0>! Contribute with <1>code</1>, <2>documentation</2>, <3>translations</3> or help by <4>supporting other users</4>.",
"description": "Resources copy (page_landingWelcome_renderResources_copy_want_to_help)"
},
"page_landingWelcome_renderVideos_alpha_demo": {
Expand Down
19 changes: 11 additions & 8 deletions add-on/src/utils/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ const browser = require('webextension-polyfill')
* @return {html} An HTML node with the translated string with anchors.
*/
const renderTranslatedLink = (message, links, attributes) => {
const regex = /<a>(.+?)<\/a>/mg
const regexLink = /<\d>(.+?)<\/\d>/mg
const regexIndex = /<(\d)>/mg
const str = browser.i18n.getMessage(message)
let match = regex.exec(str)

let output = str
let i = 0
while (match !== null) {
output = output.replace(match[0], `<a href="${links[i]}" ${attributes}>${match[1]}</a>`)
match = regex.exec(str)
i++

let matchLink = regexLink.exec(str)
while (matchLink !== null) {
let matchIndex = regexIndex.exec(matchLink[0])
while (matchIndex !== null) {
output = output.replace(matchLink[0], `<a href="${links[parseInt(matchIndex[1])]}" ${attributes}>${matchLink[1]}</a>`)
matchIndex = regexIndex.exec(str)
}
matchLink = regexLink.exec(str)
}

const template = document.createElement('template')
Expand Down

0 comments on commit 357a678

Please sign in to comment.