Skip to content

Commit

Permalink
Add an explicit zing TS plugin with a cleaner API
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Revision history
to source or target XML resource files, as well as XLIFF
translation interchange files.

- Split `pootle` and `zing` translation plugins for better clarity.

1.3 February 1, 2018

- Fix bug when extra item comment would be appended only if the
Expand Down
8 changes: 2 additions & 6 deletions doc/sample.serge
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ sync
ts
{
# (STRING) TS plugin name
plugin pootle
plugin zing

# [OPTIONAL] Plugin data. Each plugin may have specific parameters
# inside the `data` block. See the documentation for each specific
# plugin for more information.
data
{
# Unique project id (folder name) in Pootle
# Unique project id (folder name) in Zing
project_id my_project

# Path to Pootle's `manage.py` utility that is used to sync
# local translation files with its internal database
manage_py_path /path/to/pootle/manage.py
}
}

Expand Down
70 changes: 70 additions & 0 deletions lib/Serge/Sync/Plugin/TranslationService/zing.pm
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;

0 comments on commit c022e9b

Please sign in to comment.