From 995d2ffb654681f9d3ff4334b28d5ba97f4c3a20 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Sun, 3 May 2020 18:58:36 +0200 Subject: [PATCH] Make actual use of JSON format in localization (i.e. nesting) --- app/loc.js | 18 ++++++++- loc/de.json | 22 +++++----- loc/en.json | 114 +++++++++++++++++++++++++++++----------------------- loc/eo.json | 22 +++++----- 4 files changed, 103 insertions(+), 73 deletions(-) diff --git a/app/loc.js b/app/loc.js index 5425688..ed9423c 100644 --- a/app/loc.js +++ b/app/loc.js @@ -31,10 +31,24 @@ var _data = {}; * @author svartoyg */ async function retrieveData (language) { + let json try { - return (await import(`../loc/${language}.json`)).default + json = (await import(`../loc/${language}.json`)).default } catch (exception) { - return (await import(`../loc/${language.substr(0, language.indexOf('-'))}.json`)).default + json = (await import(`../loc/${language.substr(0, language.indexOf('-'))}.json`)).default + } + const map = {} + flatten(json, '', map) + return map +} + +function flatten (tree, prefix, result) { + for (const [key, value] of Object.entries(tree)) { + if (typeof value === 'string') { + result[prefix + key] = value + } else { + flatten(value, prefix + key + '.', result) + } } } diff --git a/loc/de.json b/loc/de.json index c9e57f3..1761371 100644 --- a/loc/de.json +++ b/loc/de.json @@ -1,13 +1,15 @@ { - "connectdialog.title": "Verbindung herstellen", - "connectdialog.address": "Adresse", - "connectdialog.port": "Port", - "connectdialog.username": "Nutzername", - "connectdialog.password": "Passwort", - "connectdialog.tokens": "Tokens", - "connectdialog.remove": "Entfernen", - "connectdialog.add": "Hinzufügen", - "connectdialog.cancel": "Abbrechen", - "connectdialog.connect": "Verbinden" + "connectdialog": { + "title": "Verbindung herstellen", + "address": "Adresse", + "port": "Port", + "username": "Nutzername", + "password": "Passwort", + "tokens": "Tokens", + "remove": "Entfernen", + "add": "Hinzufügen", + "cancel": "Abbrechen", + "connect": "Verbinden" + } } diff --git a/loc/en.json b/loc/en.json index 6b50d2e..d823102 100644 --- a/loc/en.json +++ b/loc/en.json @@ -1,54 +1,66 @@ { - "connectdialog.title": "Connect to Server", - "connectdialog.address": "Address", - "connectdialog.port": "Port", - "connectdialog.username": "Username", - "connectdialog.password": "Password", - "connectdialog.tokens": "Tokens", - "connectdialog.remove": "Remove", - "connectdialog.add": "Add", - "connectdialog.cancel": "Cancel", - "connectdialog.connect": "Connect", - "connectdialog.error.title": "Failed to connect", - "connectdialog.error.reason.refused": "The connection has been refused.", - "connectdialog.error.reason.version": "The server uses an incompatible version.", - "connectdialog.error.reason.username": "Your user name was rejected. Maybe try a different one?", - "connectdialog.error.reason.userpassword": "The given password is incorrect.\nThe user name you have chosen requires a special one.", - "connectdialog.error.reason.serverpassword": "The given password is incorrect.", - "connectdialog.error.reason.username_in_use": "The user name you have chosen is already in use.", - "connectdialog.error.reason.full": "The server is full.", - "connectdialog.error.reason.clientcert": "The server requires you to provide a client certificate which is not supported by this web application.", - "connectdialog.error.reason.server": "The server reports:", - "connectdialog.error.retry": "Retry", - "connectdialog.error.cancel": "Cancel", - "joindialog.title": "Mumble Voice Conference", - "joindialog.connect": "Join Conference", - "usercontextmenu.mute": "Mute", - "usercontextmenu.deafen": "Deafen", - "usercontextmenu.priority_speaker": "Priority Speaker", - "usercontextmenu.local_mute": "Local Mute", - "usercontextmenu.ignore_messages": "Ignore Messages", - "usercontextmenu.view_comment": "View Comment", - "usercontextmenu.change_comment": "Change Comment", - "usercontextmenu.reset_comment": "Reset Comment", - "usercontextmenu.view_avatar": "View Avatar", - "usercontextmenu.change_avatar": "Change Avatar", - "usercontextmenu.reset_avatar": "Reset Avatar", - "usercontextmenu.send_message": "Send Message", - "usercontextmenu.information": "Information", - "usercontextmenu.self_mute": "Self Mute", - "usercontextmenu.self_deafen": "Self Deafen", - "usercontextmenu.add_friend": "Add Friend", - "usercontextmenu.remove_friend": "Remove Friend", - "channelcontextmenu.join": "Join Channel", - "channelcontextmenu.add": "Add", - "channelcontextmenu.edit": "Edit", - "channelcontextmenu.remove": "Remove", - "channelcontextmenu.link": "Link", - "channelcontextmenu.unlink": "Unlink", - "channelcontextmenu.unlink_all": "Unlink All", - "channelcontextmenu.copy_mumble_url": "Copy Mumble URL", - "channelcontextmenu.copy_mumble_web_url": "Copy Mumble-Web URL", - "channelcontextmenu.send_message": "Send Message" + "connectdialog": { + "title": "Connect to Server", + "address": "Address", + "port": "Port", + "username": "Username", + "password": "Password", + "tokens": "Tokens", + "remove": "Remove", + "add": "Add", + "cancel": "Cancel", + "connect": "Connect", + "error": { + "title": "Failed to connect", + "reason": { + "refused": "The connection has been refused.", + "version": "The server uses an incompatible version.", + "username": "Your user name was rejected. Maybe try a different one?", + "userpassword": "The given password is incorrect.\nThe user name you have chosen requires a special one.", + "serverpassword": "The given password is incorrect.", + "username_in_use": "The user name you have chosen is already in use.", + "full": "The server is full.", + "clientcert": "The server requires you to provide a client certificate which is not supported by this web application.", + "server": "The server reports:" + }, + "retry": "Retry", + "cancel": "Cancel" + } + }, + "joindialog": { + "title": "Mumble Voice Conference", + "connect": "Join Conference" + }, + "usercontextmenu": { + "mute": "Mute", + "deafen": "Deafen", + "priority_speaker": "Priority Speaker", + "local_mute": "Local Mute", + "ignore_messages": "Ignore Messages", + "view_comment": "View Comment", + "change_comment": "Change Comment", + "reset_comment": "Reset Comment", + "view_avatar": "View Avatar", + "change_avatar": "Change Avatar", + "reset_avatar": "Reset Avatar", + "send_message": "Send Message", + "information": "Information", + "self_mute": "Self Mute", + "self_deafen": "Self Deafen", + "add_friend": "Add Friend", + "remove_friend": "Remove Friend" + }, + "channelcontextmenu": { + "channelcontextmenu.join": "Join Channel", + "channelcontextmenu.add": "Add", + "channelcontextmenu.edit": "Edit", + "channelcontextmenu.remove": "Remove", + "channelcontextmenu.link": "Link", + "channelcontextmenu.unlink": "Unlink", + "channelcontextmenu.unlink_all": "Unlink All", + "channelcontextmenu.copy_mumble_url": "Copy Mumble URL", + "channelcontextmenu.copy_mumble_web_url": "Copy Mumble-Web URL", + "channelcontextmenu.send_message": "Send Message" + } } diff --git a/loc/eo.json b/loc/eo.json index 8f8d9a1..8208a86 100644 --- a/loc/eo.json +++ b/loc/eo.json @@ -1,13 +1,15 @@ { - "connectdialog.title": "Konektado", - "connectdialog.address": "Adreso", - "connectdialog.port": "Pordo", - "connectdialog.username": "Uzantnomo", - "connectdialog.password": "Pasvorto", - "connectdialog.tokens": "Ĵetonoj", - "connectdialog.remove": "Forigi", - "connectdialog.add": "Aldoni", - "connectdialog.cancel": "Nuligi", - "connectdialog.connect": "Konekti" + "connectdialog": { + "title": "Konektado", + "address": "Adreso", + "port": "Pordo", + "username": "Uzantnomo", + "password": "Pasvorto", + "tokens": "Ĵetonoj", + "remove": "Forigi", + "add": "Aldoni", + "cancel": "Nuligi", + "connect": "Konekti" + } }