| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ABSTRACT: Locize (https://locize.com/ synchronization plugin for Serge |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Serge::Sync::Plugin::TranslationService::locize; |
|
4
|
1
|
|
|
1
|
|
16133
|
use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1823
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
24
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Serge::Util qw(subst_macros); |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
80
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use File::Find qw(find); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
48
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use File::Spec::Functions qw(catfile abs2rel); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
11
|
1
|
|
|
1
|
|
515
|
use version; |
|
|
1
|
|
|
|
|
1922
|
|
|
|
1
|
|
|
|
|
6
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = qv('0.900.0'); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub name { |
|
16
|
2
|
|
|
2
|
0
|
14605
|
return 'Locize translation software (https://locize.com/) synchronization plugin'; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub init { |
|
20
|
2
|
|
|
2
|
0
|
32
|
my $self = shift; |
|
21
|
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
17
|
$self->SUPER::init(@_); |
|
23
|
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
14
|
$self->{optimizations} = 1; |
|
25
|
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
15
|
$self->merge_schema({ |
|
27
|
|
|
|
|
|
|
config_file => 'STRING', |
|
28
|
|
|
|
|
|
|
format => 'STRING', |
|
29
|
|
|
|
|
|
|
path => 'STRING' |
|
30
|
|
|
|
|
|
|
}); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub validate_data { |
|
34
|
2
|
|
|
2
|
0
|
1668
|
my ($self) = @_; |
|
35
|
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
12
|
$self->SUPER::validate_data; |
|
37
|
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
900
|
$self->{data}->{config_file} = subst_macros($self->{data}->{config_file}); |
|
39
|
2
|
|
|
|
|
68
|
$self->{data}->{format} = subst_macros($self->{data}->{format}); |
|
40
|
2
|
|
|
|
|
56
|
$self->{data}->{path} = subst_macros($self->{data}->{path}); |
|
41
|
|
|
|
|
|
|
|
|
42
|
2
|
50
|
|
|
|
54
|
die "'config_file' not defined" unless defined $self->{data}->{config_file}; |
|
43
|
2
|
50
|
|
|
|
19
|
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}; |
|
44
|
|
|
|
|
|
|
|
|
45
|
2
|
50
|
|
|
|
70
|
die "'format' not defined" unless defined $self->{data}->{format}; |
|
46
|
|
|
|
|
|
|
|
|
47
|
2
|
50
|
|
|
|
19
|
die "'path', which is set to '$self->{data}->{path}', does not point to a valid folder." unless -d $self->{data}->{path}; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub pull_ts { |
|
51
|
2
|
|
|
2
|
0
|
711
|
my ($self, $langs) = @_; |
|
52
|
|
|
|
|
|
|
|
|
53
|
2
|
100
|
|
|
|
7
|
if ($langs) { |
|
54
|
1
|
|
|
|
|
3
|
foreach my $lang (@$langs) { |
|
55
|
2
|
|
|
|
|
13
|
my $cli_return = $self->locize_download($lang); |
|
56
|
|
|
|
|
|
|
|
|
57
|
2
|
50
|
|
|
|
167
|
if ($cli_return != 0) { |
|
58
|
0
|
|
|
|
|
0
|
return $cli_return; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} else { |
|
62
|
1
|
|
|
|
|
4
|
my $cli_return = $self->locize_download(); |
|
63
|
|
|
|
|
|
|
|
|
64
|
1
|
50
|
|
|
|
85
|
if ($cli_return != 0) { |
|
65
|
0
|
|
|
|
|
0
|
return $cli_return; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
6
|
return 0; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub push_ts { |
|
73
|
2
|
|
|
2
|
0
|
1330
|
my ($self, $langs) = @_; |
|
74
|
|
|
|
|
|
|
|
|
75
|
2
|
100
|
|
|
|
8
|
if ($langs) { |
|
76
|
1
|
|
|
|
|
4
|
foreach my $lang (@$langs) { |
|
77
|
2
|
|
|
|
|
7
|
my $cli_return = $self->locize_sync($lang); |
|
78
|
|
|
|
|
|
|
|
|
79
|
2
|
50
|
|
|
|
140
|
if ($cli_return != 0) { |
|
80
|
0
|
|
|
|
|
0
|
return $cli_return; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} else { |
|
84
|
1
|
|
|
|
|
5
|
my $cli_return = $self->locize_sync(); |
|
85
|
|
|
|
|
|
|
|
|
86
|
1
|
50
|
|
|
|
75
|
if ($cli_return != 0) { |
|
87
|
0
|
|
|
|
|
0
|
return $cli_return; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
7
|
return 0; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub locize_download { |
|
95
|
3
|
|
|
3
|
0
|
9
|
my ($self, $lang) = @_; |
|
96
|
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
7
|
my $action = 'download'; |
|
98
|
|
|
|
|
|
|
|
|
99
|
3
|
|
|
|
|
17
|
my $download_path = $self->{data}->{path}; |
|
100
|
3
|
100
|
|
|
|
32
|
$download_path = catfile($self->{data}->{path}, $self->get_locize_lang($lang)) if $lang; |
|
101
|
|
|
|
|
|
|
|
|
102
|
3
|
|
|
|
|
23
|
$action .= ' --path '.$download_path; |
|
103
|
3
|
100
|
|
|
|
12
|
$action .= ' --language '.$self->get_locize_lang($lang) if $lang; |
|
104
|
|
|
|
|
|
|
|
|
105
|
3
|
|
|
|
|
10
|
return $self->run_locize_cli($action); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub locize_sync { |
|
109
|
3
|
|
|
3
|
0
|
6
|
my ($self, $lang) = @_; |
|
110
|
|
|
|
|
|
|
|
|
111
|
3
|
|
|
|
|
8
|
my $action = 'sync'; |
|
112
|
|
|
|
|
|
|
|
|
113
|
3
|
|
|
|
|
16
|
$action .= ' --path '.$self->{data}->{path}; |
|
114
|
3
|
100
|
|
|
|
30
|
$action .= ' --language '.$self->get_locize_lang($lang) if $lang; |
|
115
|
3
|
|
|
|
|
8
|
$action .= ' --update-values true --reference-language-only false'; |
|
116
|
|
|
|
|
|
|
|
|
117
|
3
|
|
|
|
|
9
|
return $self->run_locize_cli($action); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub run_locize_cli { |
|
121
|
6
|
|
|
6
|
0
|
13
|
my ($self, $action) = @_; |
|
122
|
|
|
|
|
|
|
|
|
123
|
6
|
|
|
|
|
13
|
my $command = $action; |
|
124
|
|
|
|
|
|
|
|
|
125
|
6
|
|
|
|
|
19
|
$command .= ' --config-path '.$self->{data}->{config_file}; |
|
126
|
6
|
|
|
|
|
50
|
$command .= ' --format '.$self->{data}->{format}; |
|
127
|
|
|
|
|
|
|
|
|
128
|
6
|
|
|
|
|
41
|
$command = 'locize '.$command; |
|
129
|
6
|
|
|
|
|
191
|
print "Running '$command'...\n"; |
|
130
|
6
|
|
|
|
|
39
|
return $self->run_cmd($command); |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub get_locize_lang { |
|
134
|
6
|
|
|
6
|
0
|
14
|
my ($self, $lang) = @_; |
|
135
|
|
|
|
|
|
|
|
|
136
|
6
|
|
|
|
|
28
|
$lang =~ s/-(\w+)$/'-'.uc($1)/e; # convert e.g. 'pt-br' to 'pt-BR' |
|
|
3
|
|
|
|
|
12
|
|
|
137
|
|
|
|
|
|
|
|
|
138
|
6
|
|
|
|
|
20
|
return $lang; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |