Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yaml: Add references #117

Merged
merged 1 commit into from
May 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/Locale/Po4a/Yaml.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,25 @@ sub parse_file {
|| die "Couldn't read YAML file $filename : $!";

for my $i (0 .. $#{$yaml}) {
&walk_yaml($self, $yaml->[$i]);
&walk_yaml($self, $yaml->[$i], "");
}
$self->pushline(Encode::encode_utf8($yaml->write_string()));
}

sub walk_yaml {
my $self=shift;
my $el=shift;
my $reference=shift;


if (ref $el eq ref {}) {
print STDERR "begin a hash\n" if $self->{'options'}{'debug'};
foreach my $key (sort keys %$el) {
if (ref $el->{$key} ne ref "") {
&walk_yaml($self, $el->{$key});
&walk_yaml($self, $el->{$key}, "$reference:$key");
} else {
next if (($self->{options}{keys} ne "") and (!exists $self->{keys}{lc($key)}));
my $trans = $self->translate(Encode::encode_utf8($el->{$key}), "", "Hash Value - Key: $key", 'wrap' => 0);
my $trans = $self->translate(Encode::encode_utf8($el->{$key}), $reference, "Hash Value - Key: $key", 'wrap' => 0);
$el->{$key} = Encode::decode_utf8($trans); # Save the translation
}
}
Expand All @@ -90,16 +91,16 @@ sub walk_yaml {
print STDERR "begin an array\n" if $self->{'options'}{'debug'};
for my $i (0 .. $#{$el}) {
if (ref $el->[$i] ne ref "") {
&walk_yaml($self, $el->[$i]);
&walk_yaml($self, $el->[$i], "$reference:");
} else {
my $trans = $self->translate(Encode::encode_utf8($el->[$i]), "", "Array Element", 'wrap' => 0);
my $trans = $self->translate(Encode::encode_utf8($el->[$i]), $reference, "Array Element", 'wrap' => 0);
$el->[$i] = Encode::decode_utf8($trans); # Save the translation
}
}
}
else {
print STDERR "got a string - this is unexpected in yaml\n" if $self->{'options'}{'debug'};
my $trans = $self->translate(Encode::encode_utf8($$el), "", "String", 'wrap' => 0);
my $trans = $self->translate(Encode::encode_utf8($$el), $reference, "String", 'wrap' => 0);
$$el = Encode::decode_utf8($trans); # Save the translation
}
}
Expand Down
12 changes: 11 additions & 1 deletion t/data-32/yamlkeysoption1.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2017-11-19 19:34+0200\n"
"POT-Creation-Date: 2018-05-25 08:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -22,51 +22,61 @@ msgid "Fedora Installation Guide"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics:
#, no-wrap
msgid "Book Information"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics:
#, no-wrap
msgid "Preface"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics:
#, no-wrap
msgid "Introduction"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics:
#, no-wrap
msgid "Downloading Fedora"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics:
#, no-wrap
msgid "Installing Fedora"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics::Topics:
#, no-wrap
msgid "Preparing for Installation"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics::Topics:
#, no-wrap
msgid "Booting the Installation"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics::Topics:
#, no-wrap
msgid "Installing Using Anaconda"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics::Topics:
#, no-wrap
msgid "After the Installation"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics::Topics:
#, no-wrap
msgid "Troubleshooting"
msgstr ""
18 changes: 17 additions & 1 deletion t/data-32/yamlkeysoption2.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2017-11-19 19:34+0200\n"
"POT-Creation-Date: 2018-05-25 08:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -22,81 +22,97 @@ msgid "Fedora Installation Guide"
msgstr ""

#. type: Hash Value - Key: File
#: :Topics:
#, no-wrap
msgid "index"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics:
#, no-wrap
msgid "Book Information"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics: :Topics:
#, no-wrap
msgid "Preface"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics: :Topics:
#, no-wrap
msgid "Introduction"
msgstr ""

#. type: Hash Value - Key: File
#: :Topics:
#, no-wrap
msgid "Downloading_Fedora"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics:
#, no-wrap
msgid "Downloading Fedora"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics:
#, no-wrap
msgid "Installing Fedora"
msgstr ""

#. type: Hash Value - Key: File
#: :Topics::Topics:
#, no-wrap
msgid "Preparing_for_Installation"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics::Topics:
#, no-wrap
msgid "Preparing for Installation"
msgstr ""

#. type: Hash Value - Key: File
#: :Topics::Topics:
#, no-wrap
msgid "Booting_the_Installation"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics::Topics:
#, no-wrap
msgid "Booting the Installation"
msgstr ""

#. type: Hash Value - Key: File
#: :Topics::Topics:
#, no-wrap
msgid "Installing_Using_Anaconda"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics::Topics:
#, no-wrap
msgid "Installing Using Anaconda"
msgstr ""

#. type: Hash Value - Key: File
#: :Topics::Topics:
#, no-wrap
msgid "After_Installation"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics::Topics:
#, no-wrap
msgid "After the Installation"
msgstr ""

#. type: Hash Value - Key: Name
#: :Topics::Topics: :Topics::Topics:
#, no-wrap
msgid "Troubleshooting"
msgstr ""
Loading