Skip to content

Commit

Permalink
refactor: Improve internationalization function to accept multiple ar…
Browse files Browse the repository at this point in the history
…guments
  • Loading branch information
kabir-afk committed Jun 8, 2024
1 parent b964c94 commit f20cbaa
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ var browser = (browserType === 'firefox') ? browser : (browserType === 'chrome')
// which fetches the messages from sourceMap and replpace them with whatever the key-value pair
// for that particular message is

banana = {i18n: (msg,argument) => {
banana = {i18n: (msg,...arg) => {
let string = sourceMap.get(resArr[1])[msg];
if ((/\$1/).test(string)) {
string = string.replace(/\$1/,argument);
for (let i = 0; i < arg.length; i++) {
let regex = new RegExp(`\\$${i + 1}`);
if (regex.test(string)) {
string = string.replace(regex, arg[i]);
}
}
return string;
}};
Expand Down

0 comments on commit f20cbaa

Please sign in to comment.