line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Transifex (https://www.transifex.com) synchronization plugin for Serge |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Serge::Sync::Plugin::TranslationService::transifex; |
4
|
1
|
|
|
1
|
|
12050
|
use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1488
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Serge::Util qw(subst_macros); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
9
|
1
|
|
|
1
|
|
362
|
use version; |
|
1
|
|
|
|
|
1589
|
|
|
1
|
|
|
|
|
4
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = qv('0.902.0'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub name { |
14
|
4
|
|
|
4
|
0
|
36956
|
return 'Transifex translation software (https://www.transifex.com) synchronization plugin'; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub init { |
18
|
4
|
|
|
4
|
0
|
40
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
4
|
|
|
|
|
15
|
$self->SUPER::init(@_); |
21
|
|
|
|
|
|
|
|
22
|
4
|
|
|
|
|
23
|
$self->{optimizations} = 1; # set to undef to disable optimizations |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
|
|
16
|
$self->merge_schema({ |
25
|
|
|
|
|
|
|
root_directory => 'STRING', |
26
|
|
|
|
|
|
|
push_translations => 'BOOLEAN' |
27
|
|
|
|
|
|
|
}); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub validate_data { |
31
|
4
|
|
|
4
|
0
|
2167
|
my ($self) = @_; |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
17
|
$self->SUPER::validate_data; |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
872
|
$self->{data}->{root_directory} = subst_macros($self->{data}->{root_directory}); |
36
|
4
|
|
|
|
|
110
|
$self->{data}->{push_translations} = subst_macros($self->{data}->{push_translations}); |
37
|
|
|
|
|
|
|
|
38
|
4
|
50
|
|
|
|
92
|
die "'root_directory' not defined" unless defined $self->{data}->{root_directory}; |
39
|
4
|
100
|
|
|
|
30
|
die "'root_directory', which is set to '$self->{data}->{root_directory}', does not point to a valid file.\n" unless -d $self->{data}->{root_directory}; |
40
|
|
|
|
|
|
|
|
41
|
3
|
100
|
|
|
|
103
|
$self->{data}->{push_translations} = 1 unless defined $self->{data}->{push_translations}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub run_transifex_cli { |
45
|
6
|
|
|
6
|
0
|
14
|
my ($self, $action, $langs, $capture) = @_; |
46
|
|
|
|
|
|
|
|
47
|
6
|
|
|
|
|
10
|
my $cli_return = 0; |
48
|
|
|
|
|
|
|
|
49
|
6
|
|
|
|
|
9
|
my $command = $action; |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
|
|
24
|
$command .= ' --root '.$self->{data}->{root_directory}; |
52
|
|
|
|
|
|
|
|
53
|
6
|
100
|
|
|
|
44
|
if ($langs) { |
54
|
2
|
|
|
|
|
5
|
my @locales = map {$self->get_transifex_locale($_)} @$langs; |
|
4
|
|
|
|
|
10
|
|
55
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
6
|
my $locales_as_string = join(',', @locales); |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
7
|
$command .= ' --language '.$locales_as_string; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
6
|
|
|
|
|
13
|
$command = 'tx '.$command; |
62
|
6
|
|
|
|
|
175
|
print "Running '$command'...\n"; |
63
|
|
|
|
|
|
|
|
64
|
6
|
|
|
|
|
40
|
$cli_return = $self->run_cmd($command, $capture); |
65
|
|
|
|
|
|
|
|
66
|
6
|
|
|
|
|
350
|
return $cli_return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_transifex_locale { |
70
|
4
|
|
|
4
|
0
|
8
|
my ($self, $lang) = @_; |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
16
|
$lang =~ s/-(\w+)$/'_'.uc($1)/e; # convert e.g. 'pt-br' to 'pt_BR' |
|
2
|
|
|
|
|
10
|
|
73
|
|
|
|
|
|
|
|
74
|
4
|
|
|
|
|
20
|
return $lang; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub pull_ts { |
78
|
3
|
|
|
3
|
0
|
784
|
my ($self, $langs) = @_; |
79
|
|
|
|
|
|
|
|
80
|
3
|
|
|
|
|
9
|
return $self->run_transifex_cli('pull', $langs); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub push_ts { |
84
|
3
|
|
|
3
|
0
|
1582
|
my ($self, $langs) = @_; |
85
|
|
|
|
|
|
|
|
86
|
3
|
|
|
|
|
6
|
my $cli_return = 0; |
87
|
|
|
|
|
|
|
|
88
|
3
|
100
|
|
|
|
14
|
if ($self->{data}->{push_translations}) { |
89
|
2
|
|
|
|
|
17
|
$cli_return = $self->run_transifex_cli('push --source --translations', $langs); |
90
|
|
|
|
|
|
|
} else { |
91
|
1
|
|
|
|
|
10
|
$cli_return = $self->run_transifex_cli('push --source', $langs); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
|
|
9
|
return $cli_return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |