Commit b4ce0b84 authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis
Browse files

Change menu/notification texts on language change

parent 65940eac
...@@ -27,9 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -27,9 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<script src="static/js/jquery.js"></script> <script src="static/js/jquery.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var NOTIFICATION = COMMON.NOTIFICATION;
var MENU = COMMON.MENU;
// Setup GUI // Setup GUI
var windows = { var windows = {
"settings": null, "settings": null,
...@@ -42,7 +39,7 @@ function closeWindows() { ...@@ -42,7 +39,7 @@ function closeWindows() {
// GUI components // GUI components
var tray = new gui.Tray({ var tray = new gui.Tray({
tooltip: MENU.TITLE, tooltip: COMMON.MENU.TITLE,
icon: 'static/images/tray.png', icon: 'static/images/tray.png',
iconsAreTemplates: false iconsAreTemplates: false
}); });
...@@ -63,7 +60,7 @@ pause_item = new gui.MenuItem({ ...@@ -63,7 +60,7 @@ pause_item = new gui.MenuItem({
// pause menu item // pause menu item
icon: 'static/images/play_pause.png', icon: 'static/images/play_pause.png',
iconIsTemplate: false, iconIsTemplate: false,
label: MENU.INITIALIZING, label: COMMON.MENU.INITIALIZING,
type: 'normal', type: 'normal',
click: function() { click: function() {
if (globals.status.code == STATUS['PAUSED']) post_start(socket); if (globals.status.code == STATUS['PAUSED']) post_start(socket);
...@@ -76,7 +73,7 @@ menu.append(pause_item); ...@@ -76,7 +73,7 @@ menu.append(pause_item);
// Menu actions contents // Menu actions contents
var local_folder_menu = new gui.MenuItem({ var local_folder_menu = new gui.MenuItem({
label: MENU.FOLDER, label: COMMON.MENU.FOLDER,
icon: 'static/images/folder.png', icon: 'static/images/folder.png',
iconIsTemplate: false, iconIsTemplate: false,
enabled: false, enabled: false,
...@@ -89,7 +86,7 @@ var local_folder_menu = new gui.MenuItem({ ...@@ -89,7 +86,7 @@ var local_folder_menu = new gui.MenuItem({
menu.append(local_folder_menu); menu.append(local_folder_menu);
var pithos_page_menu = new gui.MenuItem({ var pithos_page_menu = new gui.MenuItem({
label: MENU.PITHOS, label: COMMON.MENU.PITHOS,
icon: 'static/images/pithos.png', icon: 'static/images/pithos.png',
iconIsTemplate: false, iconIsTemplate: false,
enabled: false, enabled: false,
...@@ -103,7 +100,7 @@ menu.append(pithos_page_menu); ...@@ -103,7 +100,7 @@ menu.append(pithos_page_menu);
// Settings and About // Settings and About
menu.append(new gui.MenuItem({type: 'separator'})); menu.append(new gui.MenuItem({type: 'separator'}));
var settings_menu = new gui.MenuItem({ var settings_menu = new gui.MenuItem({
label: MENU.SETTINGS, label: COMMON.MENU.SETTINGS,
icon: 'static/images/settings.png', icon: 'static/images/settings.png',
iconIsTemplate: false, iconIsTemplate: false,
enabled: false, enabled: false,
...@@ -127,6 +124,7 @@ var settings_menu = new gui.MenuItem({ ...@@ -127,6 +124,7 @@ var settings_menu = new gui.MenuItem({
log_debug('Compare ' + old_settings[key] + ' with ' + setting); log_debug('Compare ' + old_settings[key] + ' with ' + setting);
if (old_settings[key] !== setting) { if (old_settings[key] !== setting) {
log_debug('Settings have been modified - updating...'); log_debug('Settings have been modified - updating...');
check_menu_lang();
put_settings(socket, new_settings); put_settings(socket, new_settings);
get_status(socket); get_status(socket);
get_settings(socket); get_settings(socket);
...@@ -138,8 +136,8 @@ var settings_menu = new gui.MenuItem({ ...@@ -138,8 +136,8 @@ var settings_menu = new gui.MenuItem({
}); });
menu.append(settings_menu); menu.append(settings_menu);
menu.append(new gui.MenuItem({ var about_menu = new gui.MenuItem({
label: MENU.ABOUT, label: COMMON.MENU.ABOUT,
icon: 'static/images/about.png', icon: 'static/images/about.png',
iconIsTemplate: false, iconIsTemplate: false,
click: function () { click: function () {
...@@ -149,16 +147,18 @@ menu.append(new gui.MenuItem({ ...@@ -149,16 +147,18 @@ menu.append(new gui.MenuItem({
width: 860, height: 620 width: 860, height: 620
}); });
} }
})); });
menu.append(about_menu);
// Quit // Quit
menu.append(new gui.MenuItem({type: 'separator'})); menu.append(new gui.MenuItem({type: 'separator'}));
menu.append(new gui.MenuItem({ var quit_menu = new gui.MenuItem({
label: MENU.QUIT, label: COMMON.MENU.QUIT,
icon: 'static/images/exit.png', icon: 'static/images/exit.png',
iconIsTemplate: false, iconIsTemplate: false,
click: function() {post_shutdown(socket);} click: function() {post_shutdown(socket);}
})); });
menu.append(quit_menu);
function activate_menu() { function activate_menu() {
...@@ -194,13 +194,27 @@ function notify(level) { ...@@ -194,13 +194,27 @@ function notify(level) {
if (globals.notification !== globals.status.code) { if (globals.notification !== globals.status.code) {
// Notification has changed, raise notifier box // Notification has changed, raise notifier box
globals.notification = globals.status.code; globals.notification = globals.status.code;
notify_user(NOTIFICATION[globals.status.code], level); notify_user(
COMMON.NOTIFICATION[globals.status.code], level, COMMON.NOTIFIER);
}
}
function check_menu_lang() {
if (tray.tooltip !== COMMON.MENU.TITLE) {
tray.tooltip = COMMON.MENU.TITLE;
local_folder_menu.label = COMMON.MENU.FOLDER;
pithos_page_menu.label = COMMON.MENU.PITHOS;
settings_menu.label = COMMON.MENU.SETTINGS;
about_menu.label = COMMON.MENU.ABOUT;
quit_menu.label = COMMON.MENU.QUIT;
tray.menu = menu;
} }
} }
// Update progress // Update progress
window.setInterval(function() { window.setInterval(function() {
var new_progress = NOTIFICATION[globals.status.code]; check_menu_lang();
var new_progress = COMMON.NOTIFICATION[globals.status.code];
var new_pause = ''; var new_pause = '';
switch(globals.status.code) { switch(globals.status.code) {
case STATUS['UNINITIALIZED']: case STATUS['UNINITIALIZED']:
...@@ -208,29 +222,29 @@ window.setInterval(function() { ...@@ -208,29 +222,29 @@ window.setInterval(function() {
case STATUS['SHUTING DOWN']: case STATUS['SHUTING DOWN']:
notify('info'); notify('info');
deactivate_menu(); deactivate_menu();
new_pause = MENU.INACTIVE; new_pause = COMMON.MENU.INACTIVE;
break; break;
case STATUS['SYNCING']: case STATUS['SYNCING']:
notify('info'); notify('info');
activate_menu(); activate_menu();
new_progress += ', ' new_progress += ', '+ COMMON.MENU.REMAINING.replace(
+ MENU.REMAINING.replace('%s', remaining(globals.status)); '%s', remaining(globals.status));
new_pause = MENU.PAUSE; new_pause = COMMON.MENU.PAUSE;
break; break;
case STATUS['PAUSING']: case STATUS['PAUSING']:
notify('info'); notify('info');
new_progress += ', ' new_progress += ', ' + COMMON.MENU.REMAINING.replace(
+ MENU.REMAINING.replace('%s', remaining(globals.status)); '%s', remaining(globals.status));
new_pause = MENU.WAITING; new_pause = COMMON.MENU.WAITING;
pause_item.enabled = false; pause_item.enabled = false;
break; break;
case STATUS['PAUSED']: case STATUS['PAUSED']:
notify('info'); notify('info');
activate_menu(); activate_menu();
new_pause = MENU.START; new_pause = COMMON.MENU.START;
if (remaining(globals.status) > 0) if (remaining(globals.status) > 0)
new_progress += ', ' new_progress += ', '+ COMMON.MENU.REMAINING.replace(
+ MENU.REMAINING.replace('%s', remaining(globals.status)); '%s', remaining(globals.status));
break; break;
case STATUS['SETTINGS MISSING']: case STATUS['SETTINGS MISSING']:
case STATUS['AUTH URL ERROR']: case STATUS['AUTH URL ERROR']:
...@@ -238,7 +252,7 @@ window.setInterval(function() { ...@@ -238,7 +252,7 @@ window.setInterval(function() {
case STATUS['DIRECTORY ERROR']: case STATUS['DIRECTORY ERROR']:
case STATUS['CONTAINER ERROR']: case STATUS['CONTAINER ERROR']:
deactivate_menu(); deactivate_menu();
new_pause = MENU.INACTIVE; new_pause = COMMON.MENU.INACTIVE;
settings_menu.enabled = true; settings_menu.enabled = true;
notify('error'); notify('error');
break; break;
...@@ -246,7 +260,7 @@ window.setInterval(function() { ...@@ -246,7 +260,7 @@ window.setInterval(function() {
} }
if (globals.open_settings) { if (globals.open_settings) {
new_progress = MENU.SETTINGSOPEN; new_progress = COMMON.MENU.SETTINGSOPEN;
globals.open_settings = false; globals.open_settings = false;
settings_menu.click(); settings_menu.click();
deactivate_menu(); deactivate_menu();
......
var gui = require('nw.gui'); var gui = require('nw.gui');
var NOTIFIER = COMMON.NOTIFIER;
function is_up(code) { return (code / 100 >> 0) === 1; } function is_up(code) { return (code / 100 >> 0) === 1; }
function has_settings_error(code) { return (code / 200 >> 0) === 2; } function has_settings_error(code) { return (code / 200 >> 0) === 2; }
...@@ -7,11 +6,6 @@ function remaining(status) { ...@@ -7,11 +6,6 @@ function remaining(status) {
return status.unsynced - (status.synced + status.failed); return status.unsynced - (status.synced + status.failed);
} }
var ntf_title = {
'info': NOTIFIER.INFO,
'warning': NOTIFIER.WARNING,
'error': NOTIFIER.ERROR
}
var ntf_icon = { var ntf_icon = {
'info': 'static/images/ntf_info.png', 'info': 'static/images/ntf_info.png',
'warning': 'static/images/ntf_warning.png', 'warning': 'static/images/ntf_warning.png',
...@@ -30,7 +24,7 @@ var notify_menu = new gui.MenuItem({ ...@@ -30,7 +24,7 @@ var notify_menu = new gui.MenuItem({
iconIsTemplate: false, iconIsTemplate: false,
}); });
function notify_user(msg, level) { function notify_user(msg, level, ntf_title) {
var n = new Notification(ntf_title[level], { var n = new Notification(ntf_title[level], {
lang: 'utf-8', body: msg, icon: ntf_icon[level] lang: 'utf-8', body: msg, icon: ntf_icon[level]
}); });
......
...@@ -21,15 +21,16 @@ var fs = require('fs'); ...@@ -21,15 +21,16 @@ var fs = require('fs');
// Read config file // Read config file
var cnf = JSON.parse(fs.readFileSync(gui.App.argv[0], encoding='utf-8')); var cnf = JSON.parse(fs.readFileSync(gui.App.argv[0], encoding='utf-8'));
var COMMON = JSON.parse(fs.readFileSync(path.join('..', 'ui_data/common_en.json'))); function load_common(lang) {
var common_path = 'common_en.json';
var STATUS = COMMON['STATUS']; if (lang && lang !== globals.language) {
common_path = 'common_' + lang + '.json';
function log_debug(msg) { if (DEBUG) console.log(msg); } globals.language = lang;
}
function send_json(socket, msg) { return JSON.parse(fs.readFileSync(path.join('..', 'ui_data', common_path)));
socket.send(JSON.stringify(msg));
} }
var COMMON = load_common();
var STATUS = COMMON.STATUS;
var globals = { var globals = {
settings: { settings: {
...@@ -48,6 +49,12 @@ var globals = { ...@@ -48,6 +49,12 @@ var globals = {
notification: STATUS['UNINITIALIZED'] notification: STATUS['UNINITIALIZED']
} }
function log_debug(msg) { if (DEBUG) console.log(msg); }
function send_json(socket, msg) {
socket.send(JSON.stringify(msg));
}
// Protocol: requests ::: responses // Protocol: requests ::: responses
function post_ui_id(socket) { function post_ui_id(socket) {
send_json(socket, {"method": "post", "ui_id": cnf['ui_id']}) send_json(socket, {"method": "post", "ui_id": cnf['ui_id']})
...@@ -86,7 +93,6 @@ function get_status(socket) { ...@@ -86,7 +93,6 @@ function get_status(socket) {
send_json(socket, {'method': 'get', 'path': 'status'}); send_json(socket, {'method': 'get', 'path': 'status'});
} // expected response {"synced":.., "unsynced":.., "failed":..., code":..} } // expected response {"synced":.., "unsynced":.., "failed":..., code":..}
// Connect to helper // Connect to helper
var socket = new WebSocket(cnf['address']); var socket = new WebSocket(cnf['address']);
socket.onopen = function() { socket.onopen = function() {
...@@ -124,6 +130,7 @@ socket.onmessage = function(e) { ...@@ -124,6 +130,7 @@ socket.onmessage = function(e) {
break; break;
case 'get settings': case 'get settings':
log_debug(r); log_debug(r);
if (r.language !== globals.language) COMMON = load_common(r.language);
globals['settings'] = r; globals['settings'] = r;
break; break;
case 'put settings': case 'put settings':
......
...@@ -42,9 +42,9 @@ ...@@ -42,9 +42,9 @@
"QUIT": "Κλείσιμο Άγκυρας" "QUIT": "Κλείσιμο Άγκυρας"
}, },
"NOTIFIER": { "NOTIFIER": {
"INFO": "Άγκυρα", "info": "Άγκυρα",
"WARNING": "Άγκυρα - προσοχή!", "warning": "Άγκυρα - προσοχή!",
"ERROR": "Άγκυρα - σφάλμα!" "error": "Άγκυρα - σφάλμα!"
}, },
"SETTINGS": { "SETTINGS": {
"TITLE": "Ρυθμίσεις χρήστη", "TITLE": "Ρυθμίσεις χρήστη",
......
...@@ -42,9 +42,9 @@ ...@@ -42,9 +42,9 @@
"QUIT": "Quit Agkyra" "QUIT": "Quit Agkyra"
}, },
"NOTIFIER": { "NOTIFIER": {
"INFO": "Agkyra notification", "info": "Agkyra notification",
"WARNING": "Agkyra warning", "warning": "Agkyra warning",
"ERROR": "Agkyra error" "error": "Agkyra error"
}, },
"SETTINGS": { "SETTINGS": {
"TITLE": "User Settings", "TITLE": "User Settings",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment