Bugzilla – Attachment 43367 Details for
Bug 14100
Add base to make item types, branch names, sysprefs values and authorised values translatable
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14100: Better errors handling
Bug-14100-Better-errors-handling.patch (text/plain), 10.61 KB, created by
Jonathan Druart
on 2015-10-13 09:13:08 UTC
(
hide
)
Description:
Bug 14100: Better errors handling
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-10-13 09:13:08 UTC
Size:
10.61 KB
patch
obsolete
>From 90a3baaad20fc1340bbdd379e207cb15f37c3a8d Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 13 Oct 2015 09:49:55 +0100 >Subject: [PATCH] Bug 14100: Better errors handling > >This patch mainly improves the errors handling. >It's now not possible to add a translation for the same entity-code-lang >combination. >Note that we could add entity,code,lang,translation as a unique key but >translation is TEXT (TEXT column 'translation' used in key >specification without a key length). Let's see later what's is best >here. > >It also: >- wording: Translate for other languages => into >- fixes encoding issues on add/update (was just display) >- add entity and code to the title of the pop-up window > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > .../prog/en/modules/admin/itemtypes.tt | 2 +- > .../prog/en/modules/admin/localization.tt | 54 +++++++++++++++----- > svc/localization | 59 +++++++++++++--------- > 3 files changed, 77 insertions(+), 38 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt >index 8b48ad6..8e2a297 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt >@@ -126,7 +126,7 @@ Item types administration > [% END %] > <li> > <label for="description" class="required">Description: </label><input type="text" id="description" name="description" size="48" value="[% description |html %]" required="required" /> <span class="required">Required</span> >- <a href="/cgi-bin/koha/admin/localization.pl?entity=itemtypes&code=[% itemtype %]" title="Translate" rel="gb_page_center[600,500]"><i class="icon-edit"></i> Translate for other languages</a> >+ <a href="/cgi-bin/koha/admin/localization.pl?entity=itemtypes&code=[% itemtype %]" title="Translate item type [% itemtype %]" rel="gb_page_center[600,500]"><i class="icon-edit"></i> Translate into other languages</a> > </li> > [% IF ( noItemTypeImages ) %] > <li><span class="label">Image: </span>Item type images are disabled. To enable them, turn off the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=noItemTypeImages">noItemTypeImages system preference</a></li></ol> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/localization.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/localization.tt >index ab6ca72..68310e7 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/localization.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/localization.tt >@@ -17,7 +17,13 @@ > message.text("Entity %s (code %s) for lang %s has correctly been updated with '%s'".format(data.entity, data.code, data.lang, data.translation)); > } else if ( type == 'error_on_update' ) { > message = $('<div class="dialog alert"></div>'); >- message.text("An error occurred when updating this translation"); >+ if ( data.error_code == 'already_exists' ) { >+ message.text("This translation already exists for this language."); >+ } else if ( data.error_code == 'no_change' ) { >+ message.text("No change made for this translation."); >+ } else { >+ message.text("An error occurred when updating this translation."); >+ } > } else if ( type == 'success_on_delete' ) { > message = $('<div class="dialog message"></div>'); > message.text("The translation (id %s) has been removed successfully".format(data.id)); >@@ -29,7 +35,12 @@ > message.text("Translation (id %s) has been added successfully".format(data.id)); > } else if ( type == 'error_on_insert' ) { > message = $('<div class="dialog alert"></div>'); >- message.text("An error occurred when adding this translation"); >+ message = $('<div class="dialog alert"></div>'); >+ if ( data.error_code == 'already_exists' ) { >+ message.text("This translation already exists for this language."); >+ } else { >+ message.text("An error occurred when adding this translation"); >+ } > } > > $(messages).append(message); >@@ -45,14 +56,27 @@ > type: 'PUT', > url: '/cgi-bin/koha/svc/localization', > success: function (data) { >- if ( data.is_changed ) { >- $(cell).css('background-color', '#00FF00'); >- show_message({ type: 'success_on_update', data: data }); >- } >- if ( $(cell).hasClass('lang') ) { >- $(cell).text(data.lang) >- } else if ( $(cell).hasClass('translation') ) { >- $(cell).text(data.translation) >+ if ( data.error ) { >+ $(cell).css('background-color', '#FF0000'); >+ if ( $(cell).hasClass('lang') ) { >+ $(cell).text(data.lang) >+ } else if ( $(cell).hasClass('translation') ) { >+ $(cell).text(data.translation) >+ } >+ show_message({ type: 'error_on_update', data: data }); >+ } else { >+ if ( data.is_changed ) { >+ $(cell).css('background-color', '#00FF00'); >+ show_message({ type: 'success_on_update', data: data }); >+ } else { >+ $(cell).css('background-color', '#FF6400'); >+ show_message({ type: 'error_on_update', data: { error_code: 'no_change' } }); >+ } >+ if ( $(cell).hasClass('lang') ) { >+ $(cell).text(data.lang) >+ } else if ( $(cell).hasClass('translation') ) { >+ $(cell).text(data.translation) >+ } > } > }, > error: function (data) { >@@ -149,9 +173,13 @@ > type: 'POST', > url: '/cgi-bin/koha/svc/localization', > success: function (data) { >- // FIXME Should append the delete link >- table.row.add( [ data.id, data.entity, data.code, data.lang, data.translation, "" ] ).draw(); >- show_message({ type: 'success_on_insert', data: data }); >+ if ( data.error ) { >+ show_message({ type: 'error_on_insert', data: data }); >+ } else { >+ // FIXME Should append the delete link >+ table.row.add( [ data.id, data.entity, data.code, data.lang, data.translation, "" ] ).draw(); >+ show_message({ type: 'success_on_insert', data: data }); >+ } > }, > error: function (data) { > show_message({ type: 'error_on_insert', data: data }); >diff --git a/svc/localization b/svc/localization >index ebec0e2..0e4d114 100755 >--- a/svc/localization >+++ b/svc/localization >@@ -1,6 +1,7 @@ > #!/usr/bin/perl > > use Modern::Perl; >+use Encode qw( encode ); > > use C4::Service; > use Koha::Localizations; >@@ -16,7 +17,7 @@ sub get_translations { > type => $s->type, > code => $s->code, > lang => $s->lang, >- translation => $s->translation, >+ translation => Encode::encode('utf-8', $s->translation), > } > } > $response->param( translations => \@translations ); >@@ -27,26 +28,31 @@ sub update_translation { > my $id = $query->param('id'); > my $translation = $query->param('translation'); > my $lang = $query->param('lang'); >- my $localization = Koha::Localizations->find( $id ); > >+ my $localization = Koha::Localizations->find( $id ); > if ( defined $lang and $localization->lang ne $lang ) { > $localization->lang( $lang ) > } > if ( defined $translation and $localization->translation ne $translation ) { > $localization->translation( $translation ) > } >- my $is_changed; >+ my %params; > if ( $localization->is_changed ) { >- $is_changed = 1; >- $localization->store; >+ unless ( Koha::Localizations->search( { entity => $localization->entity, code => $localization->code, lang => $lang, translation => $translation, id => { '!=' => $localization->id }, } )->count ) { >+ $params{is_changed} = 1; >+ $localization->store; >+ } else { >+ $params{error} = 1; >+ $params{error_code} = 'already_exists'; >+ } > } > $response->param( >+ %params, > id => $localization->localization_id, > entity => $localization->entity, > code => $localization->code, > lang => $localization->lang, >- translation => $localization->translation, >- is_changed => $is_changed, >+ translation => Encode::encode('utf-8', $localization->translation), > ); > C4::Service->return_success( $response ); > } >@@ -56,24 +62,29 @@ sub add_translation { > my $code = $query->param('code'); > my $lang = $query->param('lang'); > my $translation = $query->param('translation'); >- my $localization = Koha::Localization->new( >- { >- entity => $entity, >- code => $code, >- lang => $lang, >- translation => $translation, >- } >- ); >- $localization->store; >- $localization->localization_id; >- $response->param( >- id => $localization->localization_id, >- entity => $localization->entity, >- code => $localization->code, >- lang => $localization->lang, >- translation => $localization->translation, >- ); > >+ unless ( Koha::Localizations->search({entity => $entity, code => $code, lang => $lang, translation => $translation, })->count ) { >+ my $localization = Koha::Localization->new( >+ { >+ entity => $entity, >+ code => $code, >+ lang => $lang, >+ translation => $translation, >+ } >+ ); >+ $localization->store; >+ $localization->localization_id; >+ $response->param( >+ id => $localization->localization_id, >+ entity => $localization->entity, >+ code => $localization->code, >+ lang => $localization->lang, >+ translation => Encode::encode('utf-8', $localization->translation), >+ ); >+ >+ } else { >+ $response->param( error => 1, error_code => 'already_exists', ); >+ } > C4::Service->return_success( $response ); > } > >-- >2.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14100
:
38727
|
40917
|
40965
|
41654
|
41659
|
41660
|
42525
|
42526
|
43110
|
43111
|
43365
|
43366
|
43367
|
43368
|
43369
|
43370
|
43394
|
43395
|
43396
|
43577
|
43602
|
43603
|
43604
|
43605
|
43606
|
43613
|
44085
|
44086
|
44087
|
44088
|
44089
|
44090
|
44094
|
44108
|
44109
|
44119
|
44151