4 use Encode
qw( encode );
7 use Koha
::Localizations
;
9 our ( $query, $response ) = C4
::Service
->init( parameters
=> 'parameters_remaining_permissions' );
11 sub get_translations
{
12 my $rs = Koha
::Localizations
->search({ entity
=> $query->param('entity'), code
=> $query->param('code') });
14 while ( my $s = $rs->next ) {
16 id
=> $s->localization_id,
20 translation
=> $s->translation,
23 $response->param( translations
=> \
@translations );
24 C4
::Service
->return_success( $response );
27 sub update_translation
{
28 my $id = $query->param('id');
29 my $translation = $query->param('translation');
30 my $lang = $query->param('lang');
32 my $localization = Koha
::Localizations
->find( $id );
33 if ( defined $lang and $localization->lang ne $lang ) {
34 $localization->lang( $lang )
36 if ( defined $translation and $localization->translation ne $translation ) {
37 $localization->translation( $translation )
41 if ( $localization->is_changed ) {
43 unless ( Koha
::Localizations
->search( { entity
=> $localization->entity, code
=> $localization->code, lang
=> $lang, localization_id
=> { '!=' => $localization->localization_id }, } )->count ) {
47 $params{error_code
} = 'already_exists';
52 id
=> $localization->localization_id,
53 entity
=> $localization->entity,
54 code
=> $localization->code,
55 lang
=> $localization->lang,
56 translation
=> $localization->translation,
57 is_changed
=> $is_changed,
59 C4
::Service
->return_success( $response );
63 my $entity = $query->param('entity');
64 my $code = $query->param('code');
65 my $lang = $query->param('lang');
66 my $translation = $query->param('translation');
68 unless ( Koha
::Localizations
->search({entity
=> $entity, code
=> $code, lang
=> $lang, })->count ) {
69 my $localization = Koha
::Localization
->new(
74 translation
=> $translation,
79 id
=> $localization->localization_id,
80 entity
=> $localization->entity,
81 code
=> $localization->code,
82 lang
=> $localization->lang,
83 translation
=> $localization->translation,
87 $response->param( error
=> 1, error_code
=> 'already_exists', );
89 C4
::Service
->return_success( $response );
92 sub delete_translation
{
93 my $id = $query->param('id');
94 Koha
::Localizations
->find($id)->delete;
95 $response->param( id
=> $id );
96 C4
::Service
->return_success( $response );
99 C4
::Service
->dispatch(
100 [ 'GET /', [ 'id' ], \
&get_translations
],
101 [ 'PUT /', [ 'id' ], \
&update_translation
],
102 [ 'POST /', [ 'entity', 'code', 'lang', 'translation' ], \
&add_translation
],
103 [ 'DELETE /', ['id'], \
&delete_translation
],