-
Notifications
You must be signed in to change notification settings - Fork 1
/
transifex-commit-translations.pl
executable file
·89 lines (69 loc) · 1.8 KB
/
transifex-commit-translations.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#! /usr/bin/perl -w
use File::Basename;
use Git::Wrapper;
our $pofile;
our $user_name = "Hakan Tandogan";
our $user_email = "hakan\@gurkensalat.com";
sub obtain_translator
{
# Fallback just in case we can't find anything...
$user_name = "Transifex Daemon";
$user_email = "transifex-daemon\@gurkensalat.com";
open (PO, "< $pofile") || die ("Can't open $pofile to read: $!");
while (<PO>)
{
if (/^\"Last-Translator\:\s/)
{
chomp;
# print "'" . $_ . "'\n";
$_ =~ s/^\"Last-Translator\:\s//;
$_ =~ s/\\n\"//;
print "'" . $_ . "'\n";
@foo = split(/[\<\>]/, $_);
# print "'" . join("', '", @foo) . "'\n";
if ($#foo > -1)
{
$user_name = $foo[0];
$user_name =~ s/\s+$//g;
}
if ($#foo > 0)
{
$user_email = $foo[1];
# Fix for polish umlaits (Sorry, Michal)
if ( $user_email eq "gatkowski.michal\@gmail.com" )
{
$user_name = "Michal Gatkowski";
}
}
}
}
close (PO);
}
sub commit_if_necessary
{
$repodir = dirname($pofile);
# print "Repo is in " . $repodir . "\n";
my $git = Git::Wrapper->new($repodir);
# print "Git wrapper is " . $git . "\n";
$git->config('user.name', $user_name);
$git->config('user.email', $user_email);
$filename = fileparse($pofile);
$git->add($filename);
# print "blah blah - '" . $pofile . "'\n";
$temp = "furbl/" . $pofile;
($foo, $bar) = split(/\/locale\//, $temp);
$message = "locale/" . $bar;
$message = "Translated " . $message . " on transifex.com";
# print "Message: '" . $message . "'\n"
$git->commit({ message => $message });
}
if ($#ARGV > -1)
{
$pofile = $ARGV[0];
if ( -e $pofile )
{
obtain_translator();
print $pofile . " - '" . $user_name . "' - '" . $user_email . "'\n";
commit_if_necessary();
}
}