From c42eae5e4a488417b30db946fd24a72af9036646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20R=C3=B6bert?= Date: Mon, 21 May 2018 23:25:20 +0200 Subject: [PATCH] Translation --- _locales/de/messages.json | 151 ++++++++++++++++++++++++++++++++++++++ _locales/en/messages.json | 151 ++++++++++++++++++++++++++++++++++++++ clearurls.js | 40 +++++++--- core_js/log.js | 25 +++++++ core_js/popup_new.js | 40 +++++++++- html/log.html | 22 ++---- html/popup.html | 100 +++++++++++++------------ 7 files changed, 448 insertions(+), 81 deletions(-) create mode 100644 _locales/de/messages.json create mode 100644 _locales/en/messages.json diff --git a/_locales/de/messages.json b/_locales/de/messages.json new file mode 100644 index 0000000..4e89490 --- /dev/null +++ b/_locales/de/messages.json @@ -0,0 +1,151 @@ +{ + "hash_status_code_1": { + "message": "Aktuell", + "description": "" + }, + + "hash_status_code_2": { + "message": "Aktuallisiert", + "description": "" + }, + + "hash_status_code_3": { + "message": "Aktuallisierung verfügbar", + "description": "" + }, + + "hash_status_code_4": { + "message": "Fehler", + "description": "" + }, + + "hash_status_code_5": { + "message": "Da ist etwas schiefgelaufen!", + "description": "" + }, + + "log_redirect": { + "message": "Diese Url wurde weiter geleitet", + "description": "" + }, + + "log_domain_blocked": { + "message": "Diese Domain wurde blockiert", + "description": "" + }, + + "check_os_log": { + "message": "ClearURLs: Protokoll-Listener wurde hinzugefügt.", + "description": "" + }, + + "log_html_page_title": { + "message": "Protokoll von ClearURLs", + "description": "" + }, + + "log_html_table_head_1": { + "message": "Vor der Verarbeitung", + "description": "" + }, + + "log_html_table_head_2": { + "message": "Nach der Verarbeitung", + "description": "" + }, + + "log_html_table_head_3": { + "message": "Regel", + "description": "" + }, + + "log_html_table_head_4": { + "message": "Zeit", + "description": "" + }, + + "log_html_reset_button": { + "message": "Zurücksetzen", + "description": "" + }, + + "popup_html_configs_head": { + "message": "Einstellungen", + "description": "" + }, + + "popup_html_configs_switch_filter": { + "message": "Filter", + "description": "" + }, + + "popup_html_configs_switch_log": { + "message": "Protokoll", + "description": "" + }, + + "popup_html_configs_switch_log_title": { + "message": "Das Protokoll wird nur lokal gespeichert. Wir empfehlen diese Funktion deaktiviert zulassen, wenn Sie sie nicht benötigen.", + "description": "" + }, + + "popup_html_configs_switch_badges": { + "message": "Zähler", + "description": "" + }, + + "popup_html_statistics_head": { + "message": "Statistik", + "description": "" + }, + + "popup_html_statistics_elements": { + "message": "Elemente", + "description": "" + }, + + "popup_html_statistics_blocked": { + "message": "Blockiert", + "description": "" + }, + + "popup_html_statistics_percentage": { + "message": "Prozentualer Anteil", + "description": "" + }, + + "popup_html_statistics_reset_button": { + "message": "Zurücksetzen", + "description": "" + }, + + "popup_html_statistics_reset_button_title": { + "message": "Setzt die globale Statistik zurück", + "description": "" + }, + + "popup_html_rules_status_head": { + "message": "Regel Status", + "description": "" + }, + + "popup_html_log_head": { + "message": "Protokoll", + "description": "" + }, + + "popup_html_log_head_title": { + "message": "Öffnet das Protokoll", + "description": "" + }, + + "core_save_on_disk": { + "message": "[ClearURLs]: Auf Festplatte gespeichert.", + "description": "" + }, + + "core_error": { + "message": "[ClearURLs]: Das Addon konnte nicht gestartet werden.", + "description": "" + } +} diff --git a/_locales/en/messages.json b/_locales/en/messages.json new file mode 100644 index 0000000..4d63ba9 --- /dev/null +++ b/_locales/en/messages.json @@ -0,0 +1,151 @@ +{ + "hash_status_code_1": { + "message": "up to date", + "description": "" + }, + + "hash_status_code_2": { + "message": "updated", + "description": "" + }, + + "hash_status_code_3": { + "message": "update available", + "description": "" + }, + + "hash_status_code_4": { + "message": "error", + "description": "" + }, + + "hash_status_code_5": { + "message": "Oops something went wrong!", + "description": "" + }, + + "log_redirect": { + "message": "This url is redirected", + "description": "" + }, + + "log_domain_blocked": { + "message": "This domain is blocked", + "description": "" + }, + + "check_os_log": { + "message": "ClearURLs: Log listener is added.", + "description": "" + }, + + "log_html_page_title": { + "message": "Log from ClearURLs", + "description": "" + }, + + "log_html_table_head_1": { + "message": "Before processing", + "description": "" + }, + + "log_html_table_head_2": { + "message": "After processing", + "description": "" + }, + + "log_html_table_head_3": { + "message": "Rule", + "description": "" + }, + + "log_html_table_head_4": { + "message": "Time", + "description": "" + }, + + "log_html_reset_button": { + "message": "Reset", + "description": "" + }, + + "popup_html_configs_head": { + "message": "Configs", + "description": "" + }, + + "popup_html_configs_switch_filter": { + "message": "Filter", + "description": "" + }, + + "popup_html_configs_switch_log": { + "message": "Logging", + "description": "" + }, + + "popup_html_configs_switch_log_title": { + "message": "The log is saved only locally. We advise against this feature if you do not need it.", + "description": "" + }, + + "popup_html_configs_switch_badges": { + "message": "Badges", + "description": "" + }, + + "popup_html_statistics_head": { + "message": "Statistics", + "description": "" + }, + + "popup_html_statistics_elements": { + "message": "Elements", + "description": "" + }, + + "popup_html_statistics_blocked": { + "message": "Blocked", + "description": "" + }, + + "popup_html_statistics_percentage": { + "message": "Percentage", + "description": "" + }, + + "popup_html_statistics_reset_button": { + "message": "Reset", + "description": "" + }, + + "popup_html_statistics_reset_button_title": { + "message": "Reset the global statistics", + "description": "" + }, + + "popup_html_rules_status_head": { + "message": "Rules-Status", + "description": "" + }, + + "popup_html_log_head": { + "message": "Log", + "description": "" + }, + + "popup_html_log_head_title": { + "message": "Open the log", + "description": "" + }, + + "core_save_on_disk": { + "message": "[ClearURLs]: Save on disk.", + "description": "" + }, + + "core_error": { + "message": "[ClearURLs]: The addon could not started.", + "description": "" + } +} diff --git a/clearurls.js b/clearurls.js index 05c15d2..51e8ac2 100644 --- a/clearurls.js +++ b/clearurls.js @@ -11,6 +11,8 @@ var siteBlockedAlert = 'javascript:void(0)'; var dataHash; var localDataHash; var os; +var rule_url = "https://raw.githubusercontent.com/KevinRoebert/ClearUrls/master/data/data.json?flush_cache=true"; +var hash_url = "https://raw.githubusercontent.com/KevinRoebert/ClearUrls/master/data/rules.hash?flush_cache=true"; var storage = []; @@ -108,13 +110,13 @@ function start(items) { switch(status_code) { - case 1: status_code = "up to date"; + case 1: status_code = "hash_status_code_1"; break; - case 2: status_code = "updated"; + case 2: status_code = "hash_status_code_2"; break; - case 3: status_code = "update available"; + case 3: status_code = "hash_status_code_3"; break; - default: status_code = "error"; + default: status_code = "hash_status_code_4"; } storage.hashStatus = status_code; @@ -129,7 +131,7 @@ function start(items) function getHash() { //Get the target hash from github - fetch("http://127.0.0.1/clearurls/rules.hash") + fetch(hash_url) .then(function(response){ var responseTextHash = response.clone().text().then(function(responseTextHash){ if(response.ok) @@ -157,7 +159,7 @@ function start(items) */ function fetchFromURL() { - fetch("http://127.0.0.1/clearurls/data.json") + fetch(rule_url) .then(checkResponse); function checkResponse(response) @@ -350,7 +352,7 @@ function start(items) { url = decodeURIComponent(re); //Log the action - pushToLog(request.url, re, "This url is redirected."); + pushToLog(request.url, re, translate('log_redirect')); return { "redirect": true, @@ -390,7 +392,7 @@ function start(items) } if(provider.isCaneling()){ - pushToLog(request.url, request.url, "This domain is blocked."); + pushToLog(request.url, request.url, translate('log_domain_blocked')); if(badges[tabid] == null) { badges[tabid] = 0; @@ -635,11 +637,14 @@ function start(items) }); } +/** + * Save every minute the temporary data to the disk. + */ +setInterval(saveOnExit, 60000); + /** * Writes the storage variable to the disk. */ -window.onbeforeunload = saveOnExit(); - function saveOnExit() { var json = {}; @@ -654,7 +659,7 @@ function saveOnExit() json[key] = value; } }); - console.log("[ClearURLs]: Save on disk."); + console.log(translate('core_save_on_disk')); browser.storage.local.set(json); } @@ -703,12 +708,23 @@ function setData(key, value) } } +/** +* Translate a string with the i18n API. +* +* @param {string} string Name of the attribute used for localization +*/ +function translate(string) +{ + return browser.i18n.getMessage(string); +} + + /** * Write error on console. */ function error() { - console.log("The addon could not started."); + console.log(translate('core_error')); } /** diff --git a/core_js/log.js b/core_js/log.js index c60a4f5..68ce68a 100644 --- a/core_js/log.js +++ b/core_js/log.js @@ -59,6 +59,31 @@ function toDate(time) * Load only when document is ready */ $(document).ready(function(){ + setText(); getLog(); $('#reset_log_btn').on("click", resetGlobalLog); }); + +/** +* Translate a string with the i18n API. +* +* @param {string} string Name of the attribute used for localization +*/ +function translate(string) +{ + return browser.i18n.getMessage(string); +} + +/** + * Set the text for the UI. + */ +function setText() +{ + document.title = translate('log_html_page_title'); + $('#page_title').text(translate('log_html_page_title')); + $('#reset_log_btn').text(translate('log_html_reset_button')); + $('#head_1').text(translate('log_html_table_head_1')); + $('#head_2').text(translate('log_html_table_head_2')); + $('#head_3').text(translate('log_html_table_head_3')); + $('#head_4').text(translate('log_html_table_head_4')); +} diff --git a/core_js/popup_new.js b/core_js/popup_new.js index 7aefdc9..f4ed3c3 100644 --- a/core_js/popup_new.js +++ b/core_js/popup_new.js @@ -66,6 +66,7 @@ function changeGlobalStatus() { core(function (ref){ ref.setData('globalStatus', element); + ref.saveOnExit(); }); } @@ -87,6 +88,7 @@ function changeTabcounter() { core(function (ref){ ref.setData('badgedStatus', element); + ref.saveOnExit(); }); } @@ -106,6 +108,7 @@ function changeLogging() var element = $('#logging').is(':checked'); core(function (ref){ ref.setData('loggingStatus', element); + ref.saveOnExit(); }); } @@ -118,10 +121,10 @@ function setHashStatus() if(hashStatus) { - element.text(hashStatus); + element.text(translate(hashStatus)); } else { - element.text('Oops something went wrong!'); + element.text(translate('hash_status_code_5')); } } @@ -156,5 +159,38 @@ $(document).ready(function(){ $('#logging').on('change', changeLogging); $('#loggingPage').attr('href', browser.extension.getURL('./html/log.html')); + setText(); + browser.storage.onChanged.addListener(changeStatistics); }); + +/** + * Set the text for the UI. + */ +function setText() +{ + $('#loggingPage').text(translate('popup_html_log_head')); + $('#loggingPage').prop('title', translate('popup_html_log_head_title')); + $('#reset_counter_btn').text(translate('popup_html_statistics_reset_button')); + $('#reset_counter_btn').prop('title', translate('popup_html_statistics_reset_button_title')); + $('#rules_status_head').text(translate('popup_html_rules_status_head')); + $('#statistics_percentage').text(translate('popup_html_statistics_percentage')); + $('#statistics_blocked').text(translate('popup_html_statistics_blocked')); + $('#statistics_elements').text(translate('popup_html_statistics_elements')); + $('#statistics_head').text(translate('popup_html_statistics_head')); + $('#configs_switch_badges').text(translate('popup_html_configs_switch_badges')); + $('#configs_switch_log').text(translate('popup_html_configs_switch_log')); + $('#configs_switch_log').prop('title', translate('popup_html_configs_switch_log_title')); + $('#configs_switch_filter').text(translate('popup_html_configs_switch_filter')); + $('#configs_head').text(translate('popup_html_configs_head')); +} + +/** +* Translate a string with the i18n API. +* +* @param {string} string Name of the attribute used for localization +*/ +function translate(string) +{ + return browser.i18n.getMessage(string); +} diff --git a/html/log.html b/html/log.html index aa37927..cf0b465 100644 --- a/html/log.html +++ b/html/log.html @@ -25,9 +25,7 @@ - - ClearURLs -
+
@@ -39,25 +37,17 @@

+ class="btn btn-danger" title="Reset the global log">

- - - - + + + + diff --git a/html/popup.html b/html/popup.html index 119d462..eb3c24d 100644 --- a/html/popup.html +++ b/html/popup.html @@ -34,67 +34,65 @@
-
Configs
+

-
- -
-
+
+ +
+
+
- -
-
-
Statistics
+
+
+
-
-
-
-
+
+
+
+
-
- Elements - -
-
+
+ + +
+
-
- Blocked - -
-
+
+ + +
+
-
- Percentage - -
-
-
-
- +
+ + +
+
+
+
+

@@ -103,7 +101,7 @@
-
Rules-Status
+
@@ -117,12 +115,12 @@
Log -
+ class="btn btn-default btn-sm btn-block"> +
-
+
+
- Before processing - - After processing - - Rule - - Time -