From a82776a6afc7676cdf8a5f7461ffe3ef22807bf5 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Fri, 18 Oct 2019 14:39:36 +0000 Subject: [PATCH] Bug 20930: Make line and column number alert translatable To test: 1. Apply patch 2. Store invalid YAML syntax into OpacHiddenItems preference 3. Observe error 4. You should also see line and column number of where the error occured --- .../intranet-tmpl/prog/en/modules/admin/preferences.tt | 1 + koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt index 920f59f77e..75fa80f42e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt @@ -213,6 +213,7 @@ var MSG_UPD_LOC_FORMAT_WARN = _("The following values are not formatted correctly:"); var MSG_INVALID = _( "Error: presence of invalid data prevents saving. Please make the corrections and try again." ); var MSG_INVALID_SYNTAX = _( "Error: Preference '%s' has invalid syntax" ); + var MSG_INVALID_SYNTAX_LOCATION = _( "Problem found at line %s, column %s." ); [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] [% Asset.js("js/ajax.js") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js index 43ee090c34..f1fd280089 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js @@ -56,9 +56,10 @@ KOHA.Preferences = { if (modified_pref in form.sysprefs) { if (form.sysprefs[modified_pref].error === 'Koha::Exceptions::Config::InvalidSyntax') { msg += ""+ MSG_INVALID_SYNTAX.format(modified_pref) + "\n"; - var error_message = form.sysprefs[modified_pref].message; - error_message = error_message.replace(/\s+at .* line \d+\.\s+$/, ''); - msg += error_message; + var location = form.sysprefs[modified_pref].message.match(/line (\d+), column (\d+)/); + if (typeof location !== 'undefined' && Array.isArray(location) && location.length===3) { + msg += ""+ MSG_INVALID_SYNTAX_LOCATION.format(location[1], location[2]) + "\n"; + } } else { msg += ""+ form.type + "\n"; } -- 2.17.1