blib/lib/Serge/Sync/Plugin/TranslationService/phrase.pm

filter: Statementstmt 100% 3 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 100% 4 / 4 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
CRAP 1.0
↑ Summary
1 # ABSTRACT: Phrase (https://phrase.com) synchronization plugin for Serge
2  
3 package Serge::Sync::Plugin::TranslationService::phrase;
4 1 ▶use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 use strict;
7  
8 use Serge::Util qw(subst_macros);
9 use version;
10  
11 our $VERSION = qv('0.904.0');
12  
13 sub name {
14 return 'Phrase translation software (https://phrase.com) synchronization plugin';
15 }
16  
17 sub init {
18 my $self = shift;
19  
20 $self->SUPER::init(@_);
21  
22 $self->{optimizations} = 1; # set to undef to disable optimizations
23  
24 $self->merge_schema({
25 config_file => 'STRING',
26 wait_for_uploads => 'BOOLEAN',
27 verbose => 'BOOLEAN'
28 });
29 }
30  
31 sub validate_data {
32 my ($self) = @_;
33  
34 $self->SUPER::validate_data;
35  
36 $self->{data}->{config_file} = subst_macros($self->{data}->{config_file});
37 $self->{data}->{wait_for_uploads} = subst_macros($self->{data}->{wait_for_uploads});
38 $self->{data}->{verbose} = subst_macros($self->{data}->{verbose});
39  
40 die "'config_file' not defined" unless defined $self->{data}->{config_file};
41 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};
42  
43 $self->{data}->{wait_for_uploads} = 1 unless defined $self->{data}->{wait_for_uploads};
44 $self->{data}->{verbose} = 0 unless defined $self->{data}->{verbose};
45 }
46  
47 sub run_phrase_cli {
48 my ($self, $action, $langs, $capture) = @_;
49  
50 local $ENV{'PHRASEAPP_CONFIG'} = $self->{data}->{config_file};
51  
52 my $command = $action;
53  
54 $command = 'phrase '.$command;
55  
56 if ($self->{data}->{verbose}) {
57 $command .= ' --verbose ';
58 }
59  
60 print "Running '$command'...\n";
61 return $self->run_cmd($command, $capture);
62 }
63  
64 sub pull_ts {
65 my ($self, $langs) = @_;
66  
67 return $self->run_phrase_cli('pull', $langs);
68 }
69  
70 sub push_ts {
71 my ($self, $langs) = @_;
72  
73 my $action = 'push';
74  
75 if ($self->{data}->{wait_for_uploads}) {
76 $action = $action.' --wait';
77 }
78  
79 $self->run_phrase_cli($action, $langs);
80 }
81  
82 1;
↑ Summary