Translation

This commit is contained in:
Kevin Röbert 2018-05-21 23:25:20 +02:00
parent ff88d9c0ae
commit c42eae5e4a
7 changed files with 448 additions and 81 deletions

151
_locales/de/messages.json Normal file
View File

@ -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": ""
}
}

151
_locales/en/messages.json Normal file
View File

@ -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": ""
}
}

View File

@ -11,6 +11,8 @@ var siteBlockedAlert = 'javascript:void(0)';
var dataHash; var dataHash;
var localDataHash; var localDataHash;
var os; 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 = []; var storage = [];
@ -108,13 +110,13 @@ function start(items)
{ {
switch(status_code) switch(status_code)
{ {
case 1: status_code = "up to date"; case 1: status_code = "hash_status_code_1";
break; break;
case 2: status_code = "updated"; case 2: status_code = "hash_status_code_2";
break; break;
case 3: status_code = "update available"; case 3: status_code = "hash_status_code_3";
break; break;
default: status_code = "error"; default: status_code = "hash_status_code_4";
} }
storage.hashStatus = status_code; storage.hashStatus = status_code;
@ -129,7 +131,7 @@ function start(items)
function getHash() function getHash()
{ {
//Get the target hash from github //Get the target hash from github
fetch("http://127.0.0.1/clearurls/rules.hash") fetch(hash_url)
.then(function(response){ .then(function(response){
var responseTextHash = response.clone().text().then(function(responseTextHash){ var responseTextHash = response.clone().text().then(function(responseTextHash){
if(response.ok) if(response.ok)
@ -157,7 +159,7 @@ function start(items)
*/ */
function fetchFromURL() function fetchFromURL()
{ {
fetch("http://127.0.0.1/clearurls/data.json") fetch(rule_url)
.then(checkResponse); .then(checkResponse);
function checkResponse(response) function checkResponse(response)
@ -350,7 +352,7 @@ function start(items)
{ {
url = decodeURIComponent(re); url = decodeURIComponent(re);
//Log the action //Log the action
pushToLog(request.url, re, "This url is redirected."); pushToLog(request.url, re, translate('log_redirect'));
return { return {
"redirect": true, "redirect": true,
@ -390,7 +392,7 @@ function start(items)
} }
if(provider.isCaneling()){ 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) if(badges[tabid] == null)
{ {
badges[tabid] = 0; 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. * Writes the storage variable to the disk.
*/ */
window.onbeforeunload = saveOnExit();
function saveOnExit() function saveOnExit()
{ {
var json = {}; var json = {};
@ -654,7 +659,7 @@ function saveOnExit()
json[key] = value; json[key] = value;
} }
}); });
console.log("[ClearURLs]: Save on disk."); console.log(translate('core_save_on_disk'));
browser.storage.local.set(json); 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. * Write error on console.
*/ */
function error() function error()
{ {
console.log("The addon could not started."); console.log(translate('core_error'));
} }
/** /**

View File

@ -59,6 +59,31 @@ function toDate(time)
* Load only when document is ready * Load only when document is ready
*/ */
$(document).ready(function(){ $(document).ready(function(){
setText();
getLog(); getLog();
$('#reset_log_btn').on("click", resetGlobalLog); $('#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'));
}

View File

@ -66,6 +66,7 @@ function changeGlobalStatus() {
core(function (ref){ core(function (ref){
ref.setData('globalStatus', element); ref.setData('globalStatus', element);
ref.saveOnExit();
}); });
} }
@ -87,6 +88,7 @@ function changeTabcounter() {
core(function (ref){ core(function (ref){
ref.setData('badgedStatus', element); ref.setData('badgedStatus', element);
ref.saveOnExit();
}); });
} }
@ -106,6 +108,7 @@ function changeLogging()
var element = $('#logging').is(':checked'); var element = $('#logging').is(':checked');
core(function (ref){ core(function (ref){
ref.setData('loggingStatus', element); ref.setData('loggingStatus', element);
ref.saveOnExit();
}); });
} }
@ -118,10 +121,10 @@ function setHashStatus()
if(hashStatus) if(hashStatus)
{ {
element.text(hashStatus); element.text(translate(hashStatus));
} }
else { 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); $('#logging').on('change', changeLogging);
$('#loggingPage').attr('href', browser.extension.getURL('./html/log.html')); $('#loggingPage').attr('href', browser.extension.getURL('./html/log.html'));
setText();
browser.storage.onChanged.addListener(changeStatistics); 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);
}

View File

@ -25,9 +25,7 @@
<span class="navbar-brand"> <span class="navbar-brand">
<span class="pull-left"><img src="../img/icon38.png" <span class="pull-left"><img src="../img/icon38.png"
width="30" height="30" alt=""></span> width="30" height="30" alt=""></span>
<span style="color: #FF7800;" class="pull-right"> <span style="color: #FF7800;" class="pull-right" id="page_title"></span><br />
ClearURLs
</span><br />
<span class="label label-warning pull-left small-version" <span class="label label-warning pull-left small-version"
id="version"></span> id="version"></span>
</span> </span>
@ -39,25 +37,17 @@
<div class="col-md-10 col-md-offset-1"> <div class="col-md-10 col-md-offset-1">
<p class="text-center"> <p class="text-center">
<button type="button" id="reset_log_btn" <button type="button" id="reset_log_btn"
class="btn btn-danger" title="Reset the global log">Reset</button> class="btn btn-danger" title="Reset the global log"></button>
</p> </p>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-bordered" <table class="table table-striped table-bordered"
width="100%" id="logTable" cellspacing="0"> width="100%" id="logTable" cellspacing="0">
<thead> <thead>
<tr> <tr>
<th data-orderable="false"> <th data-orderable="false" id="head_1"></th>
Before processing <th data-orderable="false" id="head_2"></th>
</th> <th data-orderable="false" id="head_3"></th>
<th data-orderable="false"> <th data-orderable="true" id="head_4"></th>
After processing
</th>
<th data-orderable="false">
Rule
</th>
<th data-orderable="true">
Time
</th>
</tr> </tr>
</thead> </thead>
<tbody id="tbody"> <tbody id="tbody">

View File

@ -34,67 +34,65 @@
<div class="row"> <div class="row">
<div class="col-sm-1"> <div class="col-sm-1">
<h5><b>Configs</b></h5> <h5><b id="configs_head"></b></h5>
<label class="switch"> <label class="switch">
<input type="checkbox" id="globalStatus"> <input type="checkbox" id="globalStatus">
<span class="slider round"></span> <span class="slider round"></span>
<label>Filters</label> <label id="configs_switch_filter"></label>
</label> </label>
<br> <br>
<label class="switch"> <label class="switch">
<input type="checkbox" id="logging"> <input type="checkbox" id="logging">
<span class="slider round"></span> <span class="slider round"></span>
<label title="The log is saved only locally. We advise against this feature if you do not need it."> <label id="configs_switch_log"></label>
Logging
</label> </label>
</label> <br>
<br> <label class="switch">
<label class="switch"> <input type="checkbox" id="tabcounter">
<input type="checkbox" id="tabcounter"> <span class="slider round"></span>
<span class="slider round"></span> <label id="configs_switch_badges"></label>
<label>Badges</label> </label>
</label> <div class="clearfix"></div>
<div class="clearfix"></div> <br />
<br /> </div>
</div> </div>
</div>
<div class="row"> <div class="row">
<div class="col-sm-1"> <div class="col-sm-1">
<h5><b>Statistics</b></h5> <h5><b id="statistics_head"></b></h5>
<div class="progress"> <div class="progress">
<div class="progress-bar progress-bar-danger progress-bar-striped" <div class="progress-bar progress-bar-danger progress-bar-striped"
role="progressbar" style="width: 0%" id="progress_blocked"></div> role="progressbar" style="width: 0%" id="progress_blocked"></div>
<div class="progress-bar progress-bar-info progress-bar-striped" <div class="progress-bar progress-bar-info progress-bar-striped"
role="progressbar" style="width: 100%" id="progress_non_blocked"></div> role="progressbar" style="width: 100%" id="progress_non_blocked"></div>
</div> </div>
<div> <div>
<span class="pull-left">Elements</span> <span class="pull-left" id="statistics_elements"></span>
<span class="pull-right text-info" <span class="pull-right text-info"
id="statistics_total_elements"></span> id="statistics_total_elements"></span>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
<div> <div>
<span class="pull-left">Blocked</span> <span class="pull-left" id="statistics_blocked"></span>
<span class="pull-right text-danger" <span class="pull-right text-danger"
id="statistics_value"></span> id="statistics_value"></span>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
<div> <div>
<span class="pull-left">Percentage</span> <span class="pull-left" id="statistics_percentage"></span>
<span class="pull-right text-success" <span class="pull-right text-success"
id="statistics_value_global_percentage"></span> id="statistics_value_global_percentage"></span>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
<br /> <br />
<div class="text-center"> <div class="text-center">
<button type="button" id="reset_counter_btn" <button type="button" id="reset_counter_btn"
class="btn btn-danger btn-xs" class="btn btn-danger btn-xs">
title="Reset the global statistics">Reset</button> </button>
<div class="clearfix"></div> <div class="clearfix"></div>
<br /> <br />
</div> </div>
@ -103,7 +101,7 @@
<div class="row"> <div class="row">
<div class="col-sm-1"> <div class="col-sm-1">
<h5><b>Rules-Status</b></h5> <h5><b id="rules_status_head"></b></h5>
<div class="text-center"> <div class="text-center">
<a href="https://github.com/KevinRoebert/ClearUrls/commits/master/data/data.json" <a href="https://github.com/KevinRoebert/ClearUrls/commits/master/data/data.json"
id="hashStatus" class="btn btn-primary btn-xs"></a> id="hashStatus" class="btn btn-primary btn-xs"></a>
@ -117,12 +115,12 @@
<div class="col-sm-1"> <div class="col-sm-1">
<div class="text-center"> <div class="text-center">
<a type="button" id="loggingPage" target="_blank" <a type="button" id="loggingPage" target="_blank"
class="btn btn-default btn-sm btn-block" class="btn btn-default btn-sm btn-block">
title="Open the log">Log</a> </a>
</div>
</div> </div>
</div> </div>
<br /> </div>
<br />
</div> </div>