line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Mojito (http://www.mojito.global/) synchronization plugin for Serge |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Serge::Sync::Plugin::TranslationService::mojito; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
20035
|
use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1549
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Serge::Util qw(subst_macros culture_from_lang locale_from_lang); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
84
|
|
10
|
1
|
|
|
1
|
|
370
|
use version; |
|
1
|
|
|
|
|
1644
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = qv('0.907.2'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub name { |
15
|
12
|
|
|
12
|
0
|
177625
|
return 'Mojito translation server (http://www.mojito.global/) synchronization plugin'; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub init { |
19
|
12
|
|
|
12
|
0
|
120
|
my $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
12
|
|
|
|
|
50
|
$self->SUPER::init(@_); |
22
|
|
|
|
|
|
|
|
23
|
12
|
|
|
|
|
73
|
$self->{optimizations} = 1; |
24
|
|
|
|
|
|
|
|
25
|
12
|
|
|
|
|
115
|
$self->merge_schema({ |
26
|
|
|
|
|
|
|
repository_name => 'STRING', |
27
|
|
|
|
|
|
|
application_properties => 'STRING', |
28
|
|
|
|
|
|
|
source_files_path => 'STRING', |
29
|
|
|
|
|
|
|
source_locale => 'STRING', |
30
|
|
|
|
|
|
|
localized_files_path => 'STRING', |
31
|
|
|
|
|
|
|
import_translations => 'BOOLEAN', |
32
|
|
|
|
|
|
|
inheritance_mode => 'STRING', |
33
|
|
|
|
|
|
|
file_type => 'STRING', |
34
|
|
|
|
|
|
|
status_equal_target => 'STRING', |
35
|
|
|
|
|
|
|
status_pull => 'STRING', |
36
|
|
|
|
|
|
|
destination_locales => 'ARRAY' |
37
|
|
|
|
|
|
|
}); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub validate_data { |
41
|
12
|
|
|
12
|
0
|
17854
|
my ($self) = @_; |
42
|
|
|
|
|
|
|
|
43
|
12
|
|
|
|
|
44
|
$self->SUPER::validate_data; |
44
|
|
|
|
|
|
|
|
45
|
12
|
|
|
|
|
7645
|
$self->{data}->{application_properties} = subst_macros($self->{data}->{application_properties}); |
46
|
12
|
|
|
|
|
323
|
$self->{data}->{repository_name} = subst_macros($self->{data}->{repository_name}); |
47
|
12
|
|
|
|
|
278
|
$self->{data}->{source_files_path} = subst_macros($self->{data}->{source_files_path}); |
48
|
12
|
|
|
|
|
254
|
$self->{data}->{localized_files_path} = subst_macros($self->{data}->{localized_files_path}); |
49
|
12
|
|
|
|
|
257
|
$self->{data}->{import_translations} = subst_macros($self->{data}->{import_translations}); |
50
|
12
|
|
|
|
|
618
|
$self->{data}->{source_locale} = subst_macros($self->{data}->{source_locale}); |
51
|
12
|
|
|
|
|
284
|
$self->{data}->{inheritance_mode} = subst_macros($self->{data}->{inheritance_mode}); |
52
|
12
|
|
|
|
|
269
|
$self->{data}->{file_type} = subst_macros($self->{data}->{file_type}); |
53
|
12
|
|
|
|
|
262
|
$self->{data}->{status_equal_target} = subst_macros($self->{data}->{status_equal_target}); |
54
|
12
|
|
|
|
|
263
|
$self->{data}->{status_pull} = subst_macros($self->{data}->{status_pull}); |
55
|
12
|
|
|
|
|
283
|
$self->{data}->{destination_locales} = subst_macros($self->{data}->{destination_locales}); |
56
|
|
|
|
|
|
|
|
57
|
12
|
100
|
|
|
|
271
|
die "'repository_name' not defined" unless defined $self->{data}->{repository_name}; |
58
|
|
|
|
|
|
|
|
59
|
11
|
100
|
|
|
|
79
|
if ($self->{data}->{application_properties} ne '') { |
60
|
10
|
100
|
|
|
|
70
|
die "'application_properties', which is set to '$self->{data}->{application_properties}', does not point to a valid file.\n" unless -f $self->{data}->{application_properties}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
10
|
100
|
|
|
|
247
|
die "'source_files_path' not defined" unless defined $self->{data}->{source_files_path}; |
64
|
9
|
100
|
|
|
|
70
|
die "'source_files_path', which is set to '$self->{data}->{source_files_path}', does not point to a valid directory.\n" unless -d $self->{data}->{source_files_path}; |
65
|
|
|
|
|
|
|
|
66
|
7
|
100
|
|
|
|
139
|
die "'localized_files_path' not defined" unless defined $self->{data}->{localized_files_path}; |
67
|
6
|
100
|
|
|
|
47
|
die "'localized_files_path', which is set to '$self->{data}->{localized_files_path}', does not point to a valid directory.\n" unless -d $self->{data}->{localized_files_path}; |
68
|
|
|
|
|
|
|
|
69
|
5
|
100
|
|
|
|
93
|
$self->{data}->{import_translations} = 1 unless defined $self->{data}->{import_translations}; |
70
|
5
|
100
|
|
|
|
75
|
$self->{data}->{inheritance_mode} = 'REMOVE_UNTRANSLATED' unless defined $self->{data}->{inheritance_mode}; |
71
|
5
|
100
|
|
|
|
61
|
$self->{data}->{status_pull} = 'ACCEPTED' unless defined $self->{data}->{status_pull}; |
72
|
|
|
|
|
|
|
|
73
|
5
|
100
|
66
|
|
|
59
|
if (!defined $self->{data}->{destination_locales} or scalar(@{$self->{data}->{destination_locales}}) == 0) { |
|
4
|
|
|
|
|
30
|
|
74
|
1
|
|
|
|
|
14
|
die "the list of destination languages is empty"; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub run_mojito_cli { |
79
|
11
|
|
|
11
|
0
|
24
|
my ($self, $action, $langs, $capture) = @_; |
80
|
|
|
|
|
|
|
|
81
|
11
|
|
|
|
|
17
|
my $command = $action; |
82
|
|
|
|
|
|
|
|
83
|
11
|
|
|
|
|
34
|
$command .= ' -r '.$self->{data}->{repository_name}; |
84
|
11
|
|
|
|
|
80
|
$command .= ' -s '.$self->{data}->{source_files_path}; |
85
|
11
|
100
|
|
|
|
65
|
if ($self->{data}->{application_properties} ne '') { |
86
|
8
|
|
|
|
|
55
|
$command .= ' --spring.config.location='.$self->{data}->{application_properties}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
11
|
100
|
|
|
|
71
|
if (defined $self->{data}->{source_locale}) { |
90
|
3
|
|
|
|
|
23
|
$command .= ' -sl '.$self->{data}->{source_locale}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
11
|
100
|
|
|
|
73
|
if ($langs) { |
94
|
7
|
|
|
|
|
15
|
my @locale_mapping = map {$self->get_mojito_locale_mapping($_)} @$langs; |
|
18
|
|
|
|
|
37
|
|
95
|
|
|
|
|
|
|
|
96
|
7
|
|
|
|
|
18
|
my $locale_mapping_as_string = join(',', @locale_mapping); |
97
|
|
|
|
|
|
|
|
98
|
7
|
|
|
|
|
19
|
$command .= ' --locale-mapping '.$locale_mapping_as_string; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
11
|
100
|
|
|
|
32
|
if (defined $self->{data}->{file_type}) { |
102
|
5
|
|
|
|
|
34
|
$command .= ' -ft '.$self->{data}->{file_type}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
11
|
|
|
|
|
101
|
$command = 'mojito '.$command; |
106
|
11
|
|
|
|
|
321
|
print "Running '$command'...\n"; |
107
|
|
|
|
|
|
|
|
108
|
11
|
|
|
|
|
58
|
return $self->run_cmd($command, $capture); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub get_mojito_locale_mapping { |
112
|
18
|
|
|
18
|
0
|
30
|
my ($self, $lang) = @_; |
113
|
|
|
|
|
|
|
|
114
|
18
|
|
|
|
|
39
|
my $locale = locale_from_lang($lang); |
115
|
|
|
|
|
|
|
|
116
|
18
|
|
|
|
|
181
|
my $bcp47_locale = culture_from_lang($lang); |
117
|
|
|
|
|
|
|
|
118
|
18
|
|
|
|
|
514
|
return $locale.':'.$bcp47_locale; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub pull_ts { |
122
|
4
|
|
|
4
|
0
|
1225
|
my ($self, $langs) = @_; |
123
|
|
|
|
|
|
|
|
124
|
4
|
|
|
|
|
20
|
my $action = 'pull --inheritance-mode '.$self->{data}->{inheritance_mode}.' -t '.$self->{data}->{localized_files_path}; |
125
|
4
|
|
|
|
|
51
|
$action .= ' --status '.$self->{data}->{status_pull}; |
126
|
|
|
|
|
|
|
|
127
|
4
|
|
|
|
|
31
|
return $self->run_mojito_cli($action, $self->get_langs($langs)); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub push_ts { |
131
|
4
|
|
|
4
|
0
|
2499
|
my ($self, $langs) = @_; |
132
|
|
|
|
|
|
|
|
133
|
4
|
|
|
|
|
10
|
my $cli_return = $self->run_mojito_cli('push', ()); |
134
|
|
|
|
|
|
|
|
135
|
4
|
50
|
|
|
|
219
|
if ($cli_return != 0) { |
136
|
0
|
|
|
|
|
0
|
return $cli_return; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
4
|
100
|
|
|
|
19
|
if ($self->{data}->{import_translations}) { |
140
|
3
|
|
|
|
|
22
|
my $action = 'import -t '.$self->{data}->{localized_files_path}; |
141
|
|
|
|
|
|
|
|
142
|
3
|
100
|
|
|
|
21
|
if ($self->{data}->{status_equal_target} ne '') { |
143
|
1
|
|
|
|
|
8
|
$action .= ' --status-equal-target '.$self->{data}->{status_equal_target}; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
3
|
|
|
|
|
24
|
$cli_return = $self->run_mojito_cli($action, $self->get_langs($langs)); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
4
|
|
|
|
|
171
|
return $cli_return; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub get_langs { |
153
|
7
|
|
|
7
|
0
|
14
|
my ($self, $langs) = @_; |
154
|
|
|
|
|
|
|
|
155
|
7
|
100
|
|
|
|
17
|
if (!$langs) { |
156
|
5
|
|
|
|
|
15
|
$langs = $self->{data}->{destination_locales}; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
7
|
|
|
|
|
40
|
return $langs; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |