line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Lingohub (https://www.lingohub.com) synchronization plugin for Serge |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Serge::Sync::Plugin::TranslationService::lingohub; |
4
|
1
|
|
|
1
|
|
18238
|
use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1881
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
7
|
use File::Find qw(find); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
9
|
1
|
|
|
1
|
|
6
|
use File::Spec::Functions qw(catfile abs2rel); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
10
|
1
|
|
|
1
|
|
6
|
use Serge::Util qw(subst_macros); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
83
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
471
|
use version; |
|
1
|
|
|
|
|
2007
|
|
|
1
|
|
|
|
|
6
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = qv('0.903.1'); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub name { |
17
|
7
|
|
|
7
|
0
|
105381
|
return 'Lingohub translation software (https://www.lingohub.com) synchronization plugin'; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub init { |
21
|
7
|
|
|
7
|
0
|
95
|
my $self = shift; |
22
|
|
|
|
|
|
|
|
23
|
7
|
|
|
|
|
41
|
$self->SUPER::init(@_); |
24
|
|
|
|
|
|
|
|
25
|
7
|
|
|
|
|
54
|
$self->{optimizations} = 1; # set to undef to disable optimizations |
26
|
|
|
|
|
|
|
|
27
|
7
|
|
|
|
|
64
|
$self->merge_schema({ |
28
|
|
|
|
|
|
|
project => 'STRING', |
29
|
|
|
|
|
|
|
root_directory => 'STRING', |
30
|
|
|
|
|
|
|
resource_directory => 'STRING', |
31
|
|
|
|
|
|
|
source_language => 'STRING', |
32
|
|
|
|
|
|
|
target_languages => 'ARRAY' |
33
|
|
|
|
|
|
|
}); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub validate_data { |
37
|
7
|
|
|
7
|
0
|
7513
|
my ($self) = @_; |
38
|
|
|
|
|
|
|
|
39
|
7
|
|
|
|
|
38
|
$self->SUPER::validate_data; |
40
|
|
|
|
|
|
|
|
41
|
7
|
|
|
|
|
3862
|
$self->{data}->{project} = subst_macros($self->{data}->{project}); |
42
|
7
|
|
|
|
|
258
|
$self->{data}->{root_directory} = subst_macros($self->{data}->{root_directory}); |
43
|
7
|
|
|
|
|
194
|
$self->{data}->{resource_directory} = subst_macros($self->{data}->{resource_directory}); |
44
|
7
|
|
|
|
|
184
|
$self->{data}->{source_language} = subst_macros($self->{data}->{source_language}); |
45
|
7
|
|
|
|
|
209
|
$self->{data}->{target_languages} = subst_macros($self->{data}->{target_languages}); |
46
|
|
|
|
|
|
|
|
47
|
7
|
100
|
|
|
|
197
|
die "'project' not defined" unless defined $self->{data}->{project}; |
48
|
6
|
50
|
|
|
|
57
|
die "'resource_directory' not defined" unless defined $self->{data}->{resource_directory}; |
49
|
6
|
100
|
|
|
|
51
|
die "'root_directory', which is set to '$self->{data}->{root_directory}', does not point to a valid folder." unless -d $self->{data}->{root_directory}; |
50
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
138
|
my $target_languages_count = 0; |
52
|
|
|
|
|
|
|
|
53
|
5
|
100
|
|
|
|
29
|
if (defined $self->{data}->{target_languages}) { |
54
|
4
|
|
|
|
|
46
|
$target_languages_count = scalar(@{$self->{data}->{target_languages}}); |
|
4
|
|
|
|
|
16
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
5
|
100
|
|
|
|
59
|
die "the list of target languages is empty" unless $target_languages_count != 0; |
58
|
|
|
|
|
|
|
|
59
|
4
|
100
|
|
|
|
15
|
$self->{data}->{source_language} = 'en' unless defined $self->{data}->{source_language}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub pull_ts { |
63
|
4
|
|
|
4
|
0
|
1147
|
my ($self, $langs) = @_; |
64
|
|
|
|
|
|
|
|
65
|
4
|
|
|
|
|
32
|
my $langs_to_pull = $self->get_all_langs($langs); |
66
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
14
|
foreach my $lang (@$langs_to_pull) { |
68
|
15
|
|
|
|
|
100
|
my $directory = catfile($self->{data}->{resource_directory}, $lang); |
69
|
15
|
|
|
|
|
158
|
my $cli_return = $self->run_lingohub_cli("resource:down --locale '$lang' --directory $directory --all"); |
70
|
|
|
|
|
|
|
|
71
|
15
|
50
|
|
|
|
60
|
if ($cli_return != 0) { |
72
|
0
|
|
|
|
|
0
|
return $cli_return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
4
|
|
|
|
|
16
|
return 0; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub push_ts { |
80
|
4
|
|
|
4
|
0
|
2173
|
my ($self, $langs) = @_; |
81
|
|
|
|
|
|
|
|
82
|
4
|
|
|
|
|
16
|
my $langs_to_push = $self->get_all_langs($langs); |
83
|
|
|
|
|
|
|
|
84
|
4
|
|
|
|
|
14
|
foreach my $lang (@$langs_to_push) { |
85
|
15
|
|
|
|
|
136
|
my $directory = catfile($self->{data}->{resource_directory}, $lang); |
86
|
|
|
|
|
|
|
|
87
|
15
|
|
|
|
|
171
|
my $lang_files_path = catfile($self->{data}->{root_directory}, $directory); |
88
|
15
|
|
|
|
|
127
|
my @files = $self->find_lang_files($lang_files_path); |
89
|
|
|
|
|
|
|
|
90
|
15
|
|
|
|
|
49
|
foreach my $file (@files) { |
91
|
3
|
|
|
|
|
16
|
my $resource = catfile($directory, $file); |
92
|
3
|
|
|
|
|
16
|
my $cli_return = $self->run_lingohub_cli("resource:up $resource --locale '$lang'"); |
93
|
|
|
|
|
|
|
|
94
|
3
|
50
|
|
|
|
19
|
if ($cli_return != 0) { |
95
|
0
|
|
|
|
|
0
|
return $cli_return; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
4
|
|
|
|
|
16
|
return 0; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub run_lingohub_cli { |
104
|
18
|
|
|
18
|
0
|
45
|
my ($self, $action, $capture) = @_; |
105
|
|
|
|
|
|
|
|
106
|
18
|
|
|
|
|
36
|
my $cli_return = 0; |
107
|
|
|
|
|
|
|
|
108
|
18
|
|
|
|
|
35
|
my $command = $action; |
109
|
|
|
|
|
|
|
|
110
|
18
|
|
|
|
|
41
|
$command = 'lingohub '.$command; |
111
|
18
|
|
|
|
|
64
|
$command .= " --project '$self->{data}->{project}'"; |
112
|
18
|
|
|
|
|
585
|
print "Running '$command ...\n"; |
113
|
|
|
|
|
|
|
|
114
|
18
|
|
|
|
|
152
|
$cli_return = $self->run_in($self->{data}->{root_directory}, $command, $capture); |
115
|
|
|
|
|
|
|
|
116
|
18
|
|
|
|
|
1896
|
return $cli_return; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub get_all_langs { |
120
|
8
|
|
|
8
|
0
|
21
|
my ($self, $langs) = @_; |
121
|
|
|
|
|
|
|
|
122
|
8
|
100
|
|
|
|
28
|
if (!$langs) { |
123
|
6
|
|
|
|
|
35
|
$langs = $self->{data}->{target_languages}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
8
|
|
|
|
|
67
|
my @all_langs = ($self->{data}->{source_language}); |
127
|
|
|
|
|
|
|
|
128
|
8
|
|
|
|
|
69
|
push @all_langs, @$langs; |
129
|
|
|
|
|
|
|
|
130
|
8
|
|
|
|
|
24
|
return \@all_langs; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub find_lang_files { |
134
|
15
|
|
|
15
|
0
|
35
|
my ($self, $directory) = @_; |
135
|
|
|
|
|
|
|
|
136
|
15
|
|
|
|
|
30
|
my @files = (); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
find(sub { |
139
|
6
|
100
|
|
6
|
|
301
|
push @files, abs2rel($File::Find::name, $directory) if(-f $_); |
140
|
15
|
|
|
|
|
2148
|
}, $directory); |
141
|
|
|
|
|
|
|
|
142
|
15
|
|
|
|
|
433
|
return @files; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |