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
90
91
92
93
94
95
96
97
98
|
package Travelynx::Command::translation;
# Copyright (C) 2025 Birte Kristina Friesel
#
# SPDX-License-Identifier: AGPL-3.0-or-later
use Mojo::Base 'Mojolicious::Command';
use Travelynx::Helper::Locales;
has description => 'Export translation status';
has usage => sub { shift->extract_usage };
sub run {
my ( $self, $command ) = @_;
my @locales = (qw(de-DE en-GB fr-FR hu-HU pl-PL));
my %count;
my %handle;
for my $locale (@locales) {
$handle{$locale} = Travelynx::Helper::Locales->get_handle($locale);
$handle{$locale}->fail_with('failure_handler_auto');
$count{$locale} = 0;
}
binmode( STDOUT, ':encoding(utf-8)' );
if ( not $command ) {
$self->help;
}
elsif ( $command eq 'update-ref' ) {
my @buf;
open( my $fh, '<:encoding(utf-8)', 'share/locales/de_DE.po' );
my $comment;
for my $line (<$fh>) {
chomp $line;
if ( $line =~ m{ ^ [#] \s+ (.*) $ }x ) {
push( @buf, "## $1\n" );
}
elsif ( $line =~ m{ ^ [#] , \s+ (.*) $ }x ) {
$comment = $1;
}
elsif ( $line =~ m{ ^ msgid \s+ " (.*) " $ }x ) {
my $id = $1;
push( @buf, "### ${id}\n" );
if ($comment) {
push( @buf, '*' . $comment . "*\n" );
$comment = undef;
}
for my $locale (@locales) {
my $translation = $handle{$locale}->maketext($id);
if ( $translation ne $id ) {
push( @buf, "* ${locale}: ${translation}" );
$count{$locale} += 1;
}
else {
push( @buf, "* ${locale} *missing*" );
}
}
push( @buf, q{} );
}
}
close($fh);
open( $fh, '>:encoding(utf-8)', 'share/locales/reference.md' );
say $fh '# Translation Status';
say $fh q{};
for my $locale (@locales) {
say $fh sprintf(
'* %s: %.1f%% complete (%d missing)',
$locale,
$count{$locale} * 100 / $count{'de-DE'},
$count{'de-DE'} - $count{$locale},
);
}
say $fh q{};
for my $line (@buf) {
say $fh $line;
}
close($fh);
}
else {
$self->help;
}
}
1;
__END__
=head1 SYNOPSIS
Usage: index.pl dumpstops <format> <filename>
Exports known stops to <filename>.
Right now, only the "csv" format is supported.
|