line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Lokalise (https://lokalise.co/) synchronization plugin for Serge |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Serge::Sync::Plugin::TranslationService::lokalise; |
4
|
1
|
|
|
1
|
|
17304
|
use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1621
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use File::Find qw(find); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
9
|
1
|
|
|
1
|
|
5
|
use File::Spec::Functions qw(catfile abs2rel); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
10
|
1
|
|
|
1
|
|
5
|
use Serge::Util qw(subst_macros); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
66
|
|
11
|
1
|
|
|
1
|
|
389
|
use version; |
|
1
|
|
|
|
|
1643
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = qv('0.901.2'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub name { |
16
|
8
|
|
|
8
|
0
|
96688
|
return 'Lokalise translation software (https://lokalise.co/) synchronization plugin'; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub init { |
20
|
8
|
|
|
8
|
0
|
86
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
8
|
|
|
|
|
39
|
$self->SUPER::init(@_); |
23
|
|
|
|
|
|
|
|
24
|
8
|
|
|
|
|
59
|
$self->{optimizations} = 1; |
25
|
|
|
|
|
|
|
|
26
|
8
|
|
|
|
|
58
|
$self->merge_schema({ |
27
|
|
|
|
|
|
|
config_file => 'STRING', |
28
|
|
|
|
|
|
|
resource_directory => 'STRING', |
29
|
|
|
|
|
|
|
languages => 'ARRAY', |
30
|
|
|
|
|
|
|
file_mask => 'STRING', |
31
|
|
|
|
|
|
|
file_format => 'STRING' |
32
|
|
|
|
|
|
|
}); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub validate_data { |
36
|
8
|
|
|
8
|
0
|
6787
|
my ($self) = @_; |
37
|
|
|
|
|
|
|
|
38
|
8
|
|
|
|
|
32
|
$self->SUPER::validate_data; |
39
|
|
|
|
|
|
|
|
40
|
8
|
|
|
|
|
3890
|
$self->{data}->{config_file} = subst_macros($self->{data}->{config_file}); |
41
|
8
|
|
|
|
|
239
|
$self->{data}->{cleanup_mode} = subst_macros($self->{data}->{cleanup_mode}); |
42
|
8
|
|
|
|
|
195
|
$self->{data}->{languages} = subst_macros($self->{data}->{languages}); |
43
|
8
|
|
|
|
|
181
|
$self->{data}->{file_mask} = subst_macros($self->{data}->{file_mask}); |
44
|
8
|
|
|
|
|
174
|
$self->{data}->{file_format} = subst_macros($self->{data}->{file_format}); |
45
|
|
|
|
|
|
|
|
46
|
8
|
100
|
|
|
|
169
|
die "'config_file' not defined" unless defined $self->{data}->{config_file}; |
47
|
7
|
100
|
|
|
|
54
|
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}; |
48
|
|
|
|
|
|
|
|
49
|
6
|
100
|
|
|
|
166
|
die "'resource_directory' not defined" unless defined $self->{data}->{resource_directory}; |
50
|
5
|
100
|
|
|
|
40
|
die "'resource_directory', which is set to '$self->{data}->{resource_directory}', does not point to a valid folder.\n" unless -d $self->{data}->{resource_directory}; |
51
|
|
|
|
|
|
|
|
52
|
4
|
100
|
|
|
|
75
|
die "'file_mask' not defined" unless defined $self->{data}->{file_mask}; |
53
|
3
|
100
|
|
|
|
34
|
die "'file_format' not defined" unless defined $self->{data}->{file_format}; |
54
|
|
|
|
|
|
|
|
55
|
2
|
100
|
66
|
|
|
14
|
if (!defined $self->{data}->{languages} or scalar(@{$self->{data}->{languages}}) == 0) { |
|
1
|
|
|
|
|
9
|
|
56
|
1
|
|
|
|
|
16
|
die "the list of languages is empty"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub run_lokalise_cli { |
61
|
4
|
|
|
4
|
0
|
8
|
my ($self, $action) = @_; |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
12
|
my $command = ' --config '.$self->{data}->{config_file}.' '.$action; |
64
|
|
|
|
|
|
|
|
65
|
4
|
|
|
|
|
28
|
$command = 'lokalise '.$command; |
66
|
4
|
|
|
|
|
97
|
print "Running '$command'...\n"; |
67
|
4
|
|
|
|
|
31
|
return $self->run_cmd($command); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub get_lokalise_lang { |
71
|
3
|
|
|
3
|
0
|
8
|
my ($self, $lang) = @_; |
72
|
|
|
|
|
|
|
|
73
|
3
|
|
|
|
|
12
|
$lang =~ s/-(\w+)$/'-'.uc($1)/e; # convert e.g. 'pt-br' to 'pt-BR' |
|
1
|
|
|
|
|
5
|
|
74
|
|
|
|
|
|
|
|
75
|
3
|
|
|
|
|
8
|
return $lang; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub pull_ts { |
79
|
1
|
|
|
1
|
0
|
319
|
my ($self, $langs) = @_; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
5
|
my $action = 'export --type '.$self->{data}->{file_format}; |
82
|
1
|
|
|
|
|
10
|
$action .= ' --use_original 1'; |
83
|
1
|
|
|
|
|
4
|
$action .= ' --unzip_to '.$self->{data}->{resource_directory}; |
84
|
|
|
|
|
|
|
|
85
|
1
|
50
|
|
|
|
8
|
if ($langs) { |
86
|
0
|
|
|
|
|
0
|
my @lokalise_langs = map {$self->get_lokalise_lang($_)} @$langs; |
|
0
|
|
|
|
|
0
|
|
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
my $langs_as_string = join(',', @lokalise_langs); |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
$action .= ' --langs '.$langs_as_string; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
5
|
return $self->run_lokalise_cli($action); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub push_ts { |
97
|
1
|
|
|
1
|
0
|
632
|
my ($self, $langs) = @_; |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
4
|
my $langs_to_push = $self->get_langs($langs); |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
3
|
foreach my $lang (@$langs_to_push) { |
102
|
3
|
|
|
|
|
5
|
my $action = 'import'; |
103
|
|
|
|
|
|
|
|
104
|
3
|
|
|
|
|
17
|
my $directory = catfile($self->{data}->{resource_directory}, $lang); |
105
|
3
|
|
|
|
|
26
|
my $file_mask = catfile($directory, $self->{data}->{file_mask}); |
106
|
|
|
|
|
|
|
|
107
|
3
|
|
|
|
|
24
|
$action .= ' --file '.$file_mask.' --lang_iso '.$self->get_lokalise_lang($lang); |
108
|
3
|
|
|
|
|
7
|
$action .= ' --replace 1 --fill_empty 0 --distinguish 1'; |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
7
|
my $cli_return = $self->run_lokalise_cli($action, ()); |
111
|
|
|
|
|
|
|
|
112
|
3
|
50
|
|
|
|
176
|
if ($cli_return != 0) { |
113
|
0
|
|
|
|
|
0
|
return $cli_return; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
|
|
3
|
return 0; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub get_langs { |
121
|
1
|
|
|
1
|
0
|
3
|
my ($self, $langs) = @_; |
122
|
|
|
|
|
|
|
|
123
|
1
|
50
|
|
|
|
4
|
if (!$langs) { |
124
|
1
|
|
|
|
|
5
|
$langs = $self->{data}->{languages}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
1
|
|
|
|
|
8
|
return $langs; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |