line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Crowdin (https://crowdin.com) synchronization plugin for Serge |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Serge::Sync::Plugin::TranslationService::crowdin; |
4
|
1
|
|
|
1
|
|
12702
|
use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1476
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Serge::Util qw(subst_macros); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
9
|
1
|
|
|
1
|
|
375
|
use version; |
|
1
|
|
|
|
|
1884
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = qv('0.903.0'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub name { |
14
|
5
|
|
|
5
|
0
|
50665
|
return 'Crowdin translation software (https://crowdin.com) synchronization plugin'; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub init { |
18
|
5
|
|
|
5
|
0
|
48
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
|
|
22
|
$self->SUPER::init(@_); |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
|
|
27
|
$self->{optimizations} = 1; |
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
|
|
26
|
$self->merge_schema({ |
25
|
|
|
|
|
|
|
config_file => 'STRING', |
26
|
|
|
|
|
|
|
upload_translations => 'BOOLEAN', |
27
|
|
|
|
|
|
|
import_duplicates => 'BOOLEAN', |
28
|
|
|
|
|
|
|
import_eq_suggestions => 'BOOLEAN', |
29
|
|
|
|
|
|
|
auto_approve_imported => 'BOOLEAN', |
30
|
|
|
|
|
|
|
}); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub validate_data { |
34
|
5
|
|
|
5
|
0
|
4171
|
my ($self) = @_; |
35
|
|
|
|
|
|
|
|
36
|
5
|
|
|
|
|
19
|
$self->SUPER::validate_data; |
37
|
|
|
|
|
|
|
|
38
|
5
|
|
|
|
|
1518
|
$self->{data}->{config_file} = subst_macros($self->{data}->{config_file}); |
39
|
5
|
|
|
|
|
134
|
$self->{data}->{upload_translations} = subst_macros($self->{data}->{upload_translations}); |
40
|
5
|
|
|
|
|
115
|
$self->{data}->{import_duplicates} = subst_macros($self->{data}->{import_duplicates}); |
41
|
5
|
|
|
|
|
111
|
$self->{data}->{import_eq_suggestions} = subst_macros($self->{data}->{import_eq_suggestions}); |
42
|
5
|
|
|
|
|
109
|
$self->{data}->{auto_approve_imported} = subst_macros($self->{data}->{auto_approve_imported}); |
43
|
|
|
|
|
|
|
|
44
|
5
|
50
|
|
|
|
110
|
die "'config_file' not defined" unless defined $self->{data}->{config_file}; |
45
|
5
|
100
|
|
|
|
36
|
die "'config_file', which is set to '$self->{data}->{config_file}', does not point to a valid file.\n" unless -f $self->{data}->{config_file}; |
46
|
|
|
|
|
|
|
|
47
|
4
|
100
|
|
|
|
107
|
$self->{data}->{upload_translations} = 1 unless defined $self->{data}->{upload_translations}; |
48
|
4
|
100
|
|
|
|
56
|
$self->{data}->{import_duplicates} = 0 unless defined $self->{data}->{import_duplicates}; |
49
|
4
|
100
|
|
|
|
52
|
$self->{data}->{import_eq_suggestions} = 0 unless defined $self->{data}->{import_eq_suggestions}; |
50
|
4
|
100
|
|
|
|
50
|
$self->{data}->{auto_approve_imported} = 0 unless defined $self->{data}->{auto_approve_imported}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub run_crowdin_cli { |
54
|
11
|
|
|
11
|
0
|
24
|
my ($self, $action, $langs, $capture) = @_; |
55
|
|
|
|
|
|
|
|
56
|
11
|
|
|
|
|
20
|
my $command = $action; |
57
|
|
|
|
|
|
|
|
58
|
11
|
100
|
|
|
|
59
|
if ($langs) { |
59
|
2
|
|
|
|
|
15
|
foreach my $lang (sort @$langs) { |
60
|
4
|
|
|
|
|
16
|
$lang =~ s/-(\w+)$/'-'.uc($1)/e; # convert e.g. 'pt-br' to 'pt-BR' |
|
2
|
|
|
|
|
10
|
|
61
|
4
|
|
|
|
|
9
|
$command .= " -l=$lang"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
11
|
|
|
|
|
43
|
$command .= ' --config '.$self->{data}->{config_file}; |
66
|
|
|
|
|
|
|
|
67
|
11
|
|
|
|
|
74
|
$command = 'crowdin '.$command; |
68
|
11
|
|
|
|
|
287
|
print "Running '$command'...\n"; |
69
|
11
|
|
|
|
|
61
|
return $self->run_cmd($command, $capture); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub pull_ts { |
73
|
4
|
|
|
4
|
0
|
1052
|
my ($self, $langs) = @_; |
74
|
|
|
|
|
|
|
|
75
|
4
|
|
|
|
|
11
|
return $self->run_crowdin_cli('download', $langs); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub push_ts { |
79
|
4
|
|
|
4
|
0
|
2355
|
my ($self, $langs) = @_; |
80
|
|
|
|
|
|
|
|
81
|
4
|
|
|
|
|
10
|
my $cli_return = $self->run_crowdin_cli('upload sources', ()); |
82
|
|
|
|
|
|
|
|
83
|
4
|
50
|
|
|
|
218
|
if ($cli_return != 0) { |
84
|
0
|
|
|
|
|
0
|
return $cli_return; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
4
|
100
|
|
|
|
19
|
if ($self->{data}->{upload_translations}) { |
88
|
3
|
|
|
|
|
20
|
my $action = 'upload translations'; |
89
|
3
|
100
|
|
|
|
8
|
if ($self->{data}->{import_duplicates}) { |
90
|
1
|
|
|
|
|
8
|
$action .= ' --import-duplicates'; |
91
|
|
|
|
|
|
|
} |
92
|
3
|
100
|
|
|
|
17
|
if ($self->{data}->{import_eq_suggestions}) { |
93
|
1
|
|
|
|
|
7
|
$action .= ' --import-eq-suggestions' |
94
|
|
|
|
|
|
|
} |
95
|
3
|
100
|
|
|
|
16
|
if ($self->{data}->{auto_approve_imported}) { |
96
|
1
|
|
|
|
|
7
|
$action .= ' --auto-approve-imported' |
97
|
|
|
|
|
|
|
} |
98
|
3
|
|
|
|
|
15
|
$cli_return = $self->run_crowdin_cli($action, $langs); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
4
|
|
|
|
|
163
|
return $cli_return; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |