Koha/svc/localization
Jonathan Druart 0f63f89f66 Bug 14100: Generic solution for language overlay - Item types
Test plan:
1/ update the Schema (misc/devel/update_dbix_class_files.pl)
2/ Translate templates for some languages (es-DE, de-DE for instance)
3/ Enable them in the pref (search for 'lang') for the staff interface
4/ Go on the item type admin page (admin/itemtypes.pl)
5/ Edit one
6/ Click on the 'translate for other languages' link
7/ You are now on the interface to translate the item type's description
in the languages you want. So translate some :)
8/ Go back on the item type list view (admin/itemtypes.pl)
9/ You should see the original description (non translated)
10/ Switch the language
11/ You should see the translated description in the correct language.
If the description is non translated, the original description is
displayed.

12/ On the different page where the item type is displayed, confirm that
the translated description appears.

Think further / Todo:
1/ Update all occurrences of the item type's description (DONE)
2/ Implement for authorised values
3/ Implement for syspref value (at least textarea)
4/ Implement for branch names
5/ Centralize all the translation on a single page in the admin area
...
N/ Implement a webservice to centralize all the translations and give
the ability to sync the item types/authorised values description with
the rest of the world (push and pull).

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2015-10-27 12:34:06 -03:00

92 lines
2.8 KiB
Perl
Executable file

#!/usr/bin/perl
use Modern::Perl;
use C4::Service;
use Koha::Localizations;
our ( $query, $response ) = C4::Service->init( parameters => 'parameters_remaining_permissions' );
sub get_translations {
my $rs = Koha::Localizations->search({ type => $query->param('type'), code => $query->param('code') });
my @translations;
while ( my $s = $rs->next ) {
push @translations, {
id => $s->localization_id,
type => $s->type,
code => $s->code,
lang => $s->lang,
translation => $s->translation,
}
}
$response->param( translations => \@translations );
C4::Service->return_success( $response );
}
sub update_translation {
my $id = $query->param('id');
my $translation = $query->param('translation');
my $lang = $query->param('lang');
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;
if ( $localization->is_changed ) {
$is_changed = 1;
$localization->store;
}
$response->param(
id => $localization->localization_id,
entity => $localization->entity,
code => $localization->code,
lang => $localization->lang,
translation => $localization->translation,
is_changed => $is_changed,
);
C4::Service->return_success( $response );
}
sub add_translation {
my $entity = $query->param('entity');
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,
);
C4::Service->return_success( $response );
}
sub delete_translation {
my $id = $query->param('id');
Koha::Localizations->find($id)->delete;
$response->param( id => $id );
C4::Service->return_success( $response );
}
C4::Service->dispatch(
[ 'GET /', [ 'id' ], \&get_translations ],
[ 'PUT /', [ 'id' ], \&update_translation ],
[ 'POST /', [ 'entity', 'code', 'lang', 'translation' ], \&add_translation ],
[ 'DELETE /', ['id'], \&delete_translation ],
);