View | Details | Raw Unified | Return to bug 14100
Collapse All | Expand All

(-)a/installer/data/mysql/atomicupdate/Bug_14100-add_table_localization.sql (-1 / +2 lines)
Lines 4-8 CREATE TABLE `localization` ( Link Here
4
      code varchar(64) COLLATE utf8_unicode_ci NOT NULL,
4
      code varchar(64) COLLATE utf8_unicode_ci NOT NULL,
5
      lang varchar(25) COLLATE utf8_unicode_ci NOT NULL,
5
      lang varchar(25) COLLATE utf8_unicode_ci NOT NULL,
6
      translation text COLLATE utf8_unicode_ci,
6
      translation text COLLATE utf8_unicode_ci,
7
      PRIMARY KEY (localization_id)
7
      PRIMARY KEY (localization_id),
8
      UNIQUE KEY `entity_code_lang` (`entity`,`code`,`lang`)
8
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
9
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
(-)a/installer/data/mysql/kohastructure.sql (-1 / +2 lines)
Lines 3565-3571 CREATE TABLE `localization` ( Link Here
3565
      code varchar(64) COLLATE utf8_unicode_ci NOT NULL,
3565
      code varchar(64) COLLATE utf8_unicode_ci NOT NULL,
3566
      lang varchar(25) COLLATE utf8_unicode_ci NOT NULL, --could be a foreign key
3566
      lang varchar(25) COLLATE utf8_unicode_ci NOT NULL, --could be a foreign key
3567
      translation text COLLATE utf8_unicode_ci,
3567
      translation text COLLATE utf8_unicode_ci,
3568
      PRIMARY KEY (localization_id)
3568
      PRIMARY KEY (localization_id),
3569
      UNIQUE KEY `entity_code_lang` (`entity`,`code`,`lang`)
3569
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3570
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3570
3571
3571
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3572
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt (-1 / +1 lines)
Lines 126-132 Item types administration Link Here
126
  [% END %]
126
  [% END %]
127
      <li>
127
      <li>
128
          <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>
128
          <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>
129
          <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>
129
          <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>
130
      </li>
130
      </li>
131
     [% IF ( noItemTypeImages ) %]
131
     [% IF ( noItemTypeImages ) %]
132
	 <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&amp;searchfield=noItemTypeImages">noItemTypeImages system preference</a></li></ol>
132
	 <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&amp;searchfield=noItemTypeImages">noItemTypeImages system preference</a></li></ol>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/localization.tt (-7 / +29 lines)
Lines 17-23 Link Here
17
            message.text("Entity %s (code %s) for lang %s has correctly been updated with '%s'".format(data.entity, data.code, data.lang, data.translation));
17
            message.text("Entity %s (code %s) for lang %s has correctly been updated with '%s'".format(data.entity, data.code, data.lang, data.translation));
18
        } else if ( type == 'error_on_update' ) {
18
        } else if ( type == 'error_on_update' ) {
19
            message = $('<div class="dialog alert"></div>');
19
            message = $('<div class="dialog alert"></div>');
20
            message.text("An error occurred when updating this translation");
20
            if ( data.error_code == 'already_exists' ) {
21
                message.text("A translation already exists for this language.");
22
            } else {
23
                message.text("An error occurred when updating this translation.");
24
            }
21
        } else if ( type == 'success_on_delete' ) {
25
        } else if ( type == 'success_on_delete' ) {
22
            message = $('<div class="dialog message"></div>');
26
            message = $('<div class="dialog message"></div>');
23
            message.text("The translation (id %s) has been removed successfully".format(data.id));
27
            message.text("The translation (id %s) has been removed successfully".format(data.id));
Lines 29-35 Link Here
29
            message.text("Translation (id %s) has been added successfully".format(data.id));
33
            message.text("Translation (id %s) has been added successfully".format(data.id));
30
        } else if ( type == 'error_on_insert' ) {
34
        } else if ( type == 'error_on_insert' ) {
31
            message = $('<div class="dialog alert"></div>');
35
            message = $('<div class="dialog alert"></div>');
32
            message.text("An error occurred when adding this translation");
36
            if ( data.error_code == 'already_exists' ) {
37
                message.text("A translation already exists for this language.");
38
            } else {
39
                message.text("An error occurred when adding this translation");
40
            }
33
        }
41
        }
34
42
35
        $(messages).append(message);
43
        $(messages).append(message);
Lines 48-53 Link Here
48
                if ( data.is_changed ) {
56
                if ( data.is_changed ) {
49
                    $(cell).css('background-color', '#00FF00');
57
                    $(cell).css('background-color', '#00FF00');
50
                    show_message({ type: 'success_on_update', data: data });
58
                    show_message({ type: 'success_on_update', data: data });
59
                } else {
60
                    show_message({ type: 'error_on_update', data: data });
51
                }
61
                }
52
                if ( $(cell).hasClass('lang') ) {
62
                if ( $(cell).hasClass('lang') ) {
53
                    $(cell).text(data.lang)
63
                    $(cell).text(data.lang)
Lines 91-98 Link Here
91
101
92
        var languages_select = $('<select name="lang"></select>');
102
        var languages_select = $('<select name="lang"></select>');
93
        [% FOR language IN languages %]
103
        [% FOR language IN languages %]
94
            var option = $('<option value="[% language.lang %]">[% language.description %]</option>');
104
            [% FOR sublanguage IN language.sublanguages_loop %]
95
            $(languages_select).append(option);
105
                var option;
106
                [% IF language.plural %]
107
                    option = $('<option value="[% sublanguage.rfc4646_subtag %]">[% sublanguage.native_description %] [% sublanguage.region_description %] ([% sublanguage.rfc4646_subtag %])</option>');
108
                    $(languages_select).append(option);
109
                [% ELSE %]
110
                    option = $('<option value="[% sublanguage.rfc4646_subtag %]">[% sublanguage.native_description %] ([% sublanguage.rfc4646_subtag %])</option>');
111
                [% END %]
112
                $(languages_select).append(option);
113
            [% END %]
96
        [% END %]
114
        [% END %]
97
115
98
        $("td.translation").on('focus', function(){
116
        $("td.translation").on('focus', function(){
Lines 149-157 Link Here
149
                type: 'POST',
167
                type: 'POST',
150
                url: '/cgi-bin/koha/svc/localization',
168
                url: '/cgi-bin/koha/svc/localization',
151
                success: function (data) {
169
                success: function (data) {
152
                    // FIXME Should append the delete link
170
                    if ( data.error ) {
153
                    table.row.add( [ data.id, data.entity, data.code, data.lang, data.translation, "" ] ).draw();
171
                        show_message({ type: 'error_on_insert', data: data });
154
                    show_message({ type: 'success_on_insert', data: data });
172
                    } else {
173
                        // FIXME Should append the delete link
174
                        table.row.add( [ data.id, data.entity, data.code, data.lang, data.translation, "" ] ).draw();
175
                        show_message({ type: 'success_on_insert', data: data });
176
                    }
155
                },
177
                },
156
                error: function (data) {
178
                error: function (data) {
157
                    show_message({ type: 'error_on_insert', data: data });
179
                    show_message({ type: 'error_on_insert', data: data });
(-)a/svc/localization (-34 / +42 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Encode qw( encode );
4
5
5
use C4::Service;
6
use C4::Service;
6
use Koha::Localizations;
7
use Koha::Localizations;
Lines 8-22 use Koha::Localizations; Link Here
8
our ( $query, $response ) = C4::Service->init( parameters => 'parameters_remaining_permissions' );
9
our ( $query, $response ) = C4::Service->init( parameters => 'parameters_remaining_permissions' );
9
10
10
sub get_translations {
11
sub get_translations {
11
    my $rs = Koha::Localizations->search({ type => $query->param('type'), code => $query->param('code') });
12
    my $rs = Koha::Localizations->search({ entity => $query->param('entity'), code => $query->param('code') });
12
    my @translations;
13
    my @translations;
13
    while ( my $s = $rs->next ) {
14
    while ( my $s = $rs->next ) {
14
        push @translations, {
15
        push @translations, {
15
            id => $s->localization_id,
16
              id          => Encode::encode( 'utf-8', $s->localization_id ),
16
            type => $s->type,
17
              entity      => Encode::encode( 'utf-8', $s->entity ),
17
            code => $s->code,
18
              code        => Encode::encode( 'utf-8', $s->code ),
18
            lang => $s->lang,
19
              lang        => Encode::encode( 'utf-8', $s->lang ),
19
            translation => $s->translation,
20
              translation => Encode::encode( 'utf-8', $s->translation ),
20
        }
21
        }
21
    }
22
    }
22
    $response->param( translations => \@translations );
23
    $response->param( translations => \@translations );
Lines 27-52 sub update_translation { Link Here
27
    my $id = $query->param('id');
28
    my $id = $query->param('id');
28
    my $translation = $query->param('translation');
29
    my $translation = $query->param('translation');
29
    my $lang = $query->param('lang');
30
    my $lang = $query->param('lang');
30
    my $localization = Koha::Localizations->find( $id );
31
31
32
    my $localization = Koha::Localizations->find( $id );
32
    if ( defined $lang and $localization->lang ne $lang ) {
33
    if ( defined $lang and $localization->lang ne $lang ) {
33
        $localization->lang( $lang )
34
        $localization->lang( $lang )
34
    }
35
    }
35
    if ( defined $translation and $localization->translation ne $translation ) {
36
    if ( defined $translation and $localization->translation ne $translation ) {
36
        $localization->translation( $translation )
37
        $localization->translation( $translation )
37
    }
38
    }
38
    my $is_changed;
39
    my %params;
39
    if ( $localization->is_changed ) {
40
    if ( $localization->is_changed ) {
40
        $is_changed = 1;
41
        unless ( Koha::Localizations->search( { entity => $localization->entity, code => $localization->code, lang => $lang, localization_id => { '!=' => $localization->localization_id }, } )->count ) {
41
        $localization->store;
42
            $localization->store;
43
        } else {
44
            $params{error} = 1;
45
            $params{error_code} = 'already_exists';
46
        }
42
    }
47
    }
43
    $response->param(
48
    $response->param(
44
        id          => $localization->localization_id,
49
        %params,
45
        entity      => $localization->entity,
50
        id          => Encode::encode('utf-8', $localization->localization_id),
46
        code        => $localization->code,
51
        entity      => Encode::encode('utf-8', $localization->entity),
47
        lang        => $localization->lang,
52
        code        => Encode::encode('utf-8', $localization->code),
48
        translation => $localization->translation,
53
        lang        => Encode::encode('utf-8', $localization->lang),
49
        is_changed  => $is_changed,
54
        translation => Encode::encode('utf-8', $localization->translation),
50
    );
55
    );
51
    C4::Service->return_success( $response );
56
    C4::Service->return_success( $response );
52
}
57
}
Lines 56-79 sub add_translation { Link Here
56
    my $code = $query->param('code');
61
    my $code = $query->param('code');
57
    my $lang = $query->param('lang');
62
    my $lang = $query->param('lang');
58
    my $translation = $query->param('translation');
63
    my $translation = $query->param('translation');
59
    my $localization = Koha::Localization->new(
60
        {
61
            entity => $entity,
62
            code => $code,
63
            lang => $lang,
64
            translation => $translation,
65
        }
66
    );
67
    $localization->store;
68
    $localization->localization_id;
69
    $response->param(
70
        id          => $localization->localization_id,
71
        entity      => $localization->entity,
72
        code        => $localization->code,
73
        lang        => $localization->lang,
74
        translation => $localization->translation,
75
    );
76
64
65
    unless ( Koha::Localizations->search({entity => $entity, code => $code, lang => $lang, })->count ) {
66
        my $localization = Koha::Localization->new(
67
            {
68
                entity => $entity,
69
                code => $code,
70
                lang => $lang,
71
                translation => $translation,
72
            }
73
        );
74
        $localization->store;
75
        $response->param(
76
            id          => Encode::encode('utf-8', $localization->localization_id),
77
            entity      => Encode::encode('utf-8', $localization->entity),
78
            code        => Encode::encode('utf-8', $localization->code),
79
            lang        => Encode::encode('utf-8', $localization->lang),
80
            translation => Encode::encode('utf-8', $localization->translation),
81
        );
82
83
    } else {
84
        $response->param( error => 1, error_code => 'already_exists', );
85
    }
77
    C4::Service->return_success( $response );
86
    C4::Service->return_success( $response );
78
}
87
}
79
88
80
- 

Return to bug 14100