From 182d752ac689b80f82028ab340df6ede2fbd5566 Mon Sep 17 00:00:00 2001 From: Cranberry <20140992+cranberry3148@users.noreply.github.com> Date: Fri, 3 Jan 2025 00:06:06 +0100 Subject: [PATCH] add: chrome based translation for modal --- .../public/_locales/de/messages.json | 65 +++++++++++++++++++ .../public/_locales/en/messages.json | 65 +++++++++++++++++++ Extension-React/public/content.js | 62 +++++++++++------- Extension-React/public/manifest.json | 1 + 4 files changed, 168 insertions(+), 25 deletions(-) create mode 100644 Extension-React/public/_locales/de/messages.json create mode 100644 Extension-React/public/_locales/en/messages.json diff --git a/Extension-React/public/_locales/de/messages.json b/Extension-React/public/_locales/de/messages.json new file mode 100644 index 00000000..e1da0e66 --- /dev/null +++ b/Extension-React/public/_locales/de/messages.json @@ -0,0 +1,65 @@ +{ + "language_name": { + "message": "Deutsch" + }, + "apply": { + "message": "Anwenden" + }, + "ignore": { + "message": "Ignorieren" + }, + "syrup_logo": { + "message": "Syrup Logo" + }, + "show_extension": { + "message": "Erweiterung anzeigen" + }, + "no_auto_apply_setup": { + "message": "Keine Seitenvoreinstellung für diese Seite." + }, + "click_apply_to_try_them_all": { + "message": "Klicke auf \"Anwenden\", um alle zu scannen." + }, + "syrup_found_coupons": { + "message": "Syrup hat Gutscheine gefunden!" + }, + "got_it": { + "message": "Okay" + }, + "testing_coupons": { + "message": "Teste Gutscheine..." + }, + "testing_coupon_current_of_total": { + "message": "Teste Gutschein %currentIndex% von %total%" + }, + "cancel": { + "message": "Abbrechen" + }, + "use_best": { + "message": "Besten verwenden" + }, + "testing_cancelled": { + "message": "Scan abgebrochen." + }, + "scan_was_stopped_no_coupons_applied": { + "message": "Scan wurde abgebrochen. Keine Gutscheine angewendet." + }, + "we_found_the_best_coupon": { + "message": "Wir haben den besten Gutschein gefunden!" + }, + "applied_coupon_and_saved_savings_new_total": { + "message": "Gutschein \"%bestCoupon%\" angewendet und %savings% eingespart. Neuer Gesamtwert: %finalPrice%" + }, + "no_better_price_found": { + "message": "Kein besserer Preis gefunden." + }, + "all_coupons_tested_but_none_lowered_your_total": { + "message": "Alle Gutscheine getestet, aber kein Preis war besser." + }, + "now_trying_best_so_far": { + "message": "Teste nun \"%currentCoupon%\". Bester Preis bis jetzt: %bestPriceSoFar%" + }, + "best_price_so_far": { + "message": "Bester Preis bis jetzt: %bestPriceSoFar%" + } +} \ No newline at end of file diff --git a/Extension-React/public/_locales/en/messages.json b/Extension-React/public/_locales/en/messages.json new file mode 100644 index 00000000..2b942ef3 --- /dev/null +++ b/Extension-React/public/_locales/en/messages.json @@ -0,0 +1,65 @@ +{ + "language_name": { + "message": "English" + }, + "apply": { + "message": "Apply" + }, + "ignore": { + "message": "Ignore" + }, + "syrup_logo": { + "message": "Syrup Logo" + }, + "show_extension": { + "message": "Show Extension" + }, + "no_auto_apply_setup": { + "message": "No auto-apply setup for this site." + }, + "click_apply_to_try_them_all": { + "message": "Click Apply to try them all." + }, + "syrup_found_coupons": { + "message": "Syrup found coupons!" + }, + "got_it": { + "message": "Got it" + }, + "testing_coupons": { + "message": "Testing Coupons..." + }, + "testing_coupon_current_of_total": { + "message": "Testing coupon %currentIndex% of %total%" + }, + "cancel": { + "message": "Cancel" + }, + "use_best": { + "message": "Use Best" + }, + "testing_cancelled": { + "message": "Testing Cancelled." + }, + "scan_was_stopped_no_coupons_applied": { + "message": "Scan was stopped. No coupons applied." + }, + "we_found_the_best_coupon": { + "message": "We found the best coupon!" + }, + "applied_coupon_and_saved_savings_new_total": { + "message": "Applied coupon \"%bestCoupon%\" and saved %savings%. New total: %finalPrice%" + }, + "no_better_price_found": { + "message": "No better price found." + }, + "all_coupons_tested_but_none_lowered_your_total": { + "message": "All coupons tested, but none lowered your total." + }, + "now_trying_best_so_far": { + "message": "Now trying \"%currentCoupon%\". Best price so far: %bestPriceSoFar%" + }, + "best_price_so_far": { + "message": "Best price so far: $%bestPriceSoFar%" + } +} \ No newline at end of file diff --git a/Extension-React/public/content.js b/Extension-React/public/content.js index 5cfdff06..ea819b47 100644 --- a/Extension-React/public/content.js +++ b/Extension-React/public/content.js @@ -74,6 +74,15 @@ }); } + function getTranslation(key, data = {}) { + let translated = chrome.i18n.getMessage(key); + for (const [name, value] of Object.entries(data)) { + translated = translated.replace(new RegExp(`%${name}%`, "g"), value); + } + return translated; + } + const __ = getTranslation; + function isVisible(el) { if (!el) return false; return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length); @@ -87,7 +96,6 @@ function replaceValue(selector, value) { const el = document.querySelector(selector); - console.log("setting", el, "to", value); if (el) { el.value = value; // Fire typical events to ensure the page sees the input @@ -318,7 +326,7 @@ container.innerHTML = `
Click Apply to try them all.
+${__("click_apply_to_try_them_all")}
No auto-apply setup for this site.
+${__("no_auto_apply_setup")}