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
|
|
14522
|
use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1647
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
21
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Serge::Util qw(subst_macros); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
9
|
1
|
|
|
1
|
|
5
|
use File::Find qw(find); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
10
|
1
|
|
|
1
|
|
6
|
use File::Spec::Functions qw(catfile abs2rel); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
11
|
1
|
|
|
1
|
|
412
|
use version; |
|
1
|
|
|
|
|
1652
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = qv('0.901.2'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub name { |
16
|
2
|
|
|
2
|
0
|
13084
|
return 'Locize translation software (https://locize.com/) synchronization plugin'; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub init { |
20
|
2
|
|
|
2
|
0
|
28
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
16
|
$self->SUPER::init(@_); |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
13
|
$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
|
1473
|
my ($self) = @_; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
11
|
$self->SUPER::validate_data; |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
815
|
$self->{data}->{config_file} = subst_macros($self->{data}->{config_file}); |
39
|
2
|
|
|
|
|
64
|
$self->{data}->{format} = subst_macros($self->{data}->{format}); |
40
|
2
|
|
|
|
|
46
|
$self->{data}->{path} = subst_macros($self->{data}->{path}); |
41
|
|
|
|
|
|
|
|
42
|
2
|
50
|
|
|
|
42
|
die "'config_file' not defined" unless defined $self->{data}->{config_file}; |
43
|
2
|
50
|
|
|
|
16
|
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
|
|
|
|
63
|
die "'format' not defined" unless defined $self->{data}->{format}; |
46
|
|
|
|
|
|
|
|
47
|
2
|
50
|
|
|
|
15
|
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
|
704
|
my ($self, $langs) = @_; |
52
|
|
|
|
|
|
|
|
53
|
2
|
100
|
|
|
|
6
|
if ($langs) { |
54
|
1
|
|
|
|
|
3
|
foreach my $lang (@$langs) { |
55
|
2
|
|
|
|
|
13
|
my $cli_return = $self->locize_download($lang); |
56
|
|
|
|
|
|
|
|
57
|
2
|
50
|
|
|
|
142
|
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
|
|
|
|
80
|
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
|
1319
|
my ($self, $langs) = @_; |
74
|
|
|
|
|
|
|
|
75
|
2
|
100
|
|
|
|
6
|
if ($langs) { |
76
|
1
|
|
|
|
|
2
|
foreach my $lang (@$langs) { |
77
|
2
|
|
|
|
|
6
|
my $cli_return = $self->locize_sync($lang); |
78
|
|
|
|
|
|
|
|
79
|
2
|
50
|
|
|
|
119
|
if ($cli_return != 0) { |
80
|
0
|
|
|
|
|
0
|
return $cli_return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} else { |
84
|
1
|
|
|
|
|
4
|
my $cli_return = $self->locize_sync(); |
85
|
|
|
|
|
|
|
|
86
|
1
|
50
|
|
|
|
62
|
if ($cli_return != 0) { |
87
|
0
|
|
|
|
|
0
|
return $cli_return; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
6
|
return 0; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub locize_download { |
95
|
3
|
|
|
3
|
0
|
8
|
my ($self, $lang) = @_; |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
6
|
my $action = 'download'; |
98
|
|
|
|
|
|
|
|
99
|
3
|
|
|
|
|
13
|
my $download_path = $self->{data}->{path}; |
100
|
3
|
100
|
|
|
|
25
|
$download_path = catfile($self->{data}->{path}, $self->get_locize_lang($lang)) if $lang; |
101
|
|
|
|
|
|
|
|
102
|
3
|
|
|
|
|
19
|
$action .= ' --path '.$download_path; |
103
|
3
|
100
|
|
|
|
10
|
$action .= ' --language '.$self->get_locize_lang($lang) if $lang; |
104
|
|
|
|
|
|
|
|
105
|
3
|
|
|
|
|
8
|
return $self->run_locize_cli($action); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub locize_sync { |
109
|
3
|
|
|
3
|
0
|
7
|
my ($self, $lang) = @_; |
110
|
|
|
|
|
|
|
|
111
|
3
|
|
|
|
|
5
|
my $action = 'sync'; |
112
|
|
|
|
|
|
|
|
113
|
3
|
|
|
|
|
13
|
$action .= ' --path '.$self->{data}->{path}; |
114
|
3
|
100
|
|
|
|
26
|
$action .= ' --language '.$self->get_locize_lang($lang) if $lang; |
115
|
3
|
|
|
|
|
6
|
$action .= ' --update-values true --reference-language-only false'; |
116
|
|
|
|
|
|
|
|
117
|
3
|
|
|
|
|
7
|
return $self->run_locize_cli($action); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub run_locize_cli { |
121
|
6
|
|
|
6
|
0
|
10
|
my ($self, $action) = @_; |
122
|
|
|
|
|
|
|
|
123
|
6
|
|
|
|
|
12
|
my $command = $action; |
124
|
|
|
|
|
|
|
|
125
|
6
|
|
|
|
|
15
|
$command .= ' --config-path '.$self->{data}->{config_file}; |
126
|
6
|
|
|
|
|
43
|
$command .= ' --format '.$self->{data}->{format}; |
127
|
|
|
|
|
|
|
|
128
|
6
|
|
|
|
|
34
|
$command = 'locize '.$command; |
129
|
6
|
|
|
|
|
177
|
print "Running '$command'...\n"; |
130
|
6
|
|
|
|
|
37
|
return $self->run_cmd($command); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub get_locize_lang { |
134
|
6
|
|
|
6
|
0
|
12
|
my ($self, $lang) = @_; |
135
|
|
|
|
|
|
|
|
136
|
6
|
|
|
|
|
20
|
$lang =~ s/-(\w+)$/'-'.uc($1)/e; # convert e.g. 'pt-br' to 'pt-BR' |
|
3
|
|
|
|
|
12
|
|
137
|
|
|
|
|
|
|
|
138
|
6
|
|
|
|
|
18
|
return $lang; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |