-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an explicit
zing
TS plugin with a cleaner API
Reason: while `pootle` plugin can technically work both with Pootle and Zing, it's cleaner to have a dedicated `zing` plugin with proper documentation and a cleaner API (`executable` parameter instead of `manage_py_path`) going forward. `pootle` plugin will still ship with Serge for backward compatibility but will be essentially deprecated, as Pootle open-source project itself is no longer maintained.
- Loading branch information
Igor Afanasyev
committed
Jun 12, 2019
1 parent
5ab7700
commit c022e9b
Showing
3 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package Serge::Sync::Plugin::TranslationService::zing; | ||
use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner; | ||
|
||
use strict; | ||
|
||
use Serge::Util qw(subst_macros); | ||
|
||
sub name { | ||
return 'Zing translation server (https://evernote.github.io/zing/) synchronization plugin'; | ||
} | ||
|
||
sub init { | ||
my $self = shift; | ||
|
||
$self->SUPER::init(@_); | ||
|
||
$self->{optimizations} = 1; # set to undef to disable optimizations | ||
|
||
$self->merge_schema({ | ||
project_id => 'STRING', | ||
executable => 'STRING', | ||
}); | ||
} | ||
|
||
sub validate_data { | ||
my ($self) = @_; | ||
|
||
$self->SUPER::validate_data; | ||
|
||
$self->{data}->{project_id} = subst_macros($self->{data}->{project_id}); | ||
$self->{data}->{executable} = subst_macros($self->{data}->{executable}); | ||
|
||
$self->{data}->{executable} = $ENV{ZING_EXECUTABLE} || 'zing' unless defined $self->{data}->{executable}; | ||
die "'project_id' not defined" unless defined $self->{data}->{project_id}; | ||
} | ||
|
||
sub run_manage_py { | ||
my ($self, $action, $langs, $capture) = @_; | ||
|
||
my $command = $action.' --project='.$self->{data}->{project_id}; | ||
|
||
if ($langs) { | ||
foreach my $lang (sort @$langs) { | ||
$lang =~ s/-(\w+)$/'_'.uc($1)/e; # convert e.g. 'pt-br' to 'pt_BR' | ||
$command .= " --language=$lang"; | ||
} | ||
} | ||
|
||
$command = $self->{data}->{executable}.' '.$command; | ||
print "Running '$command'...\n"; | ||
return $self->run_cmd($command, $capture); | ||
} | ||
|
||
sub pull_ts { | ||
my ($self, $langs) = @_; | ||
|
||
my $force = $self->{optimizations} ? '' : ' --overwrite'; | ||
|
||
return $self->run_manage_py('sync_stores --skip-missing'.$force, $langs); | ||
} | ||
|
||
sub push_ts { | ||
my ($self, $langs) = @_; | ||
|
||
my $force = $self->{optimizations} ? '' : ' --force'; | ||
|
||
$self->run_manage_py('update_stores'.$force, $langs); | ||
} | ||
|
||
1; |