From 1774cf0b1520041874592ecf861b7f9e299aac56 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 25 Feb 2015 17:12:17 -0500 Subject: [PATCH] allow language strings in menu items --- install/data/navigation.json | 32 +++++++++++++------------- public/src/admin/general/navigation.js | 12 +++++++--- src/navigation/admin.js | 10 +++++++- src/upgrade.js | 4 ++-- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/install/data/navigation.json b/install/data/navigation.json index 9d690fd415..b36b6fb8e7 100644 --- a/install/data/navigation.json +++ b/install/data/navigation.json @@ -2,46 +2,46 @@ { "id": "unread-count", "route": "/unread", - "title": "[[global:header.unread]]", + "title": "\\[\\[global:header.unread\\]\\]", "enabled": true, "iconClass": "fa-inbox", "textClass": "visible-xs-inline", - "text": "[[global:header.unread]]", + "text": "\\[\\[global:header.unread\\]\\]", "properties": { "loggedIn": true } }, { "route": "/recent", - "title": "[[global:header.recent]]", + "title": "\\[\\[global:header.recent\\]\\]", "enabled": true, "iconClass": "fa-clock-o", "textClass": "visible-xs-inline", - "text": "[[global:header.recent]]" + "text": "\\[\\[global:header.recen\\t\\]]" }, { "route": "/tags", - "title": "[[global:header.tags]]", + "title": "\\[\\[global:header.tags\\]\\]", "enabled": true, "iconClass": "fa-tags", "textClass": "visible-xs-inline", - "text": "[[global:header.tags]]" + "text": "\\[\\[global:header.tag\\s\\]]" }, { "route": "/popular", - "title": "[[global:header.popular]]", + "title": "\\[\\[global:header.popular\\]\\]", "enabled": true, "iconClass": "fa-fire", "textClass": "visible-xs-inline", - "text": "[[global:header.popular]]" + "text": "\\[\\[global:header.popula\\r\\]]" }, { "route": "/users", - "title": "[[global:header.users]]", + "title": "\\[\\[global:header.users\\]\\]", "enabled": true, "iconClass": "fa-user", "textClass": "visible-xs-inline", - "text": "[[global:header.users]]", + "text": "\\[\\[global:header.users\\]\\]", "properties": { "loggedIn": true, "hideIfPrivate": true @@ -49,31 +49,31 @@ }, { "route": "/groups", - "title": "[[global:header.groups]]", + "title": "\\[\\[global:header.groups\\]\\]", "enabled": true, "iconClass": "fa-group", "textClass": "visible-xs-inline", - "text": "[[global:header.groups]]" + "text": "\\[\\[global:header.group\\s\\]]" }, { "route": "/admin", "target": "_top", - "title": "[[global:header.admin]]", + "title": "\\[\\[global:header.admin\\]\\]", "enabled": true, "iconClass": "fa-cogs", "textClass": "visible-xs-inline", - "text": "[[global:header.admin]]", + "text": "\\[\\[global:header.admin\\]\\]", "properties": { "adminOnly": true } }, { "route": "/search", - "title": "[[global:header.search]]", + "title": "\\[\\[global:header.search\\]\\]", "enabled": true, "iconClass": "fa-search", "textClass": "visible-xs-inline", - "text": "[[global:header.search]]", + "text": "\\[\\[global:header.search\\]\\]", "properties": { "installed": { "search": true diff --git a/public/src/admin/general/navigation.js b/public/src/admin/general/navigation.js index a5b1efb439..a26f2e3da4 100644 --- a/public/src/admin/general/navigation.js +++ b/public/src/admin/general/navigation.js @@ -1,5 +1,5 @@ "use strict"; -/* global define, app, ajaxify, socket, templates, bootbox */ +/* global define, app, ajaxify, socket, templates, bootbox, translator */ define('admin/general/navigation', function() { var navigation = {}, @@ -8,6 +8,12 @@ define('admin/general/navigation', function() { navigation.init = function() { available = JSON.parse(ajaxify.variables.get('available')); + $('#enabled').html(translator.unescape($('#enabled').html())); + translator.translate(translator.unescape($('#available').html()), function(html) { + $('#available').html(html); + }); + + $('#enabled') .on('click', '.delete', remove) .on('click', '.toggle', toggle) @@ -33,7 +39,7 @@ define('admin/general/navigation', function() { data = id === 'custom' ? {} : available[id]; templates.parse('admin/general/navigation', 'enabled', {enabled: [data]}, function(li) { - li = $(li); + li = $(translator.unescape(li)); el.after(li); el.remove(); }); @@ -47,7 +53,7 @@ define('admin/general/navigation', function() { data = {}; form.forEach(function(input) { - data[input.name] = input.value; + data[input.name] = translator.escape(input.value); }); available.forEach(function(item) { diff --git a/src/navigation/admin.js b/src/navigation/admin.js index 15726001d1..6ae28d179e 100644 --- a/src/navigation/admin.js +++ b/src/navigation/admin.js @@ -4,13 +4,21 @@ var admin = {}, async = require('async'), plugins = require('../plugins'), - db = require('../database'); + db = require('../database'), + translator = require('../../public/src/translator'); admin.save = function(data, callback) { var order = Object.keys(data), items = data.map(function(item, idx) { var data = {}; + + for (var i in item) { + if (item.hasOwnProperty(i)) { + item[i] = typeof item[i] === 'string' ? translator.escape(item[i]) : item[i]; + } + } + data[idx] = item; return JSON.stringify(data); }); diff --git a/src/upgrade.js b/src/upgrade.js index fee22659dd..3a52020ca5 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -21,7 +21,7 @@ var db = require('./database'), schemaDate, thisSchemaDate, // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema - latestSchema = Date.UTC(2015, 1, 25, 4); + latestSchema = Date.UTC(2015, 1, 25, 6); Upgrade.check = function(callback) { db.get('schemaDate', function(err, value) { @@ -943,7 +943,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = Date.UTC(2015, 1, 25, 4); + thisSchemaDate = Date.UTC(2015, 1, 25, 6); if (schemaDate < thisSchemaDate) { updatesMade = true; winston.info('[2015/02/25] Upgrading menu items to dynamic navigation system');