po: Add support for mo files in underlays
In order to support translated basewiki and other underlays, we need support for mo files in underlays. The code did not allow this before, because if a mo file was in an underlay, then it might try to update it, and its pot, and write to the underlay, which is guaranteed to either fail due to permissions, or be undesirable. To fix, my approach is to just detect if a mo or pot file that is about to be updated is in an underlay, and skip updating it. This seems to work well: - If the mo is out of date in the underlay, it won't get updated, but this would probably be due to a problem in the underlay, or more likely, the wiki is being rebuilt and so it *thinks* the mo is out of date, but it's really not (and it would be a waste of time to rebuild it anyway). - If a page from the basewiki is edited, it is saved to the srcdir, which causes generation of an updated mo and pot also in the srcdir; the underlay stops being used for that page, and everything seems to work. Note that I am not including an underlay search directory for pot files. They *seem* to be unnecessary for the underlay, since the mo files in there never need to be updated.master
parent
eeeda1295f
commit
eca2dbe67f
|
@ -151,11 +151,24 @@ sub checkconfig () {
|
||||||
|
|
||||||
push @{$config{wiki_file_prune_regexps}}, qr/\.pot$/;
|
push @{$config{wiki_file_prune_regexps}}, qr/\.pot$/;
|
||||||
|
|
||||||
|
# Translated versions of the underlays are added if available.
|
||||||
|
foreach my $underlay ("basewiki", map { m/^\Q$config{underlaydirbase}\E\/*(.*)/ } reverse @{$config{underlaydirs}}) {
|
||||||
|
next if $underlay=~/^locale\//;
|
||||||
|
|
||||||
|
# Add underlay containing the pot files.
|
||||||
|
#add_underlay("locale/pot/$underlay")
|
||||||
|
# if -d "$config{underlaydirbase}/locale/pot/$underlay";
|
||||||
|
|
||||||
|
# Add underlays containing the po files for slave languages.
|
||||||
|
foreach my $ll (keys %{$config{po_slave_languages}}) {
|
||||||
|
add_underlay("locale/mo/$underlay")
|
||||||
|
if -d "$config{underlaydirbase}/locale/mo/$underlay";
|
||||||
|
}
|
||||||
|
|
||||||
if ($config{po_master_language}{code} ne 'en') {
|
if ($config{po_master_language}{code} ne 'en') {
|
||||||
# use translated underlay directories in preference
|
# Add underlay containing translated source files
|
||||||
# to the untranslated ones
|
# for the master language.
|
||||||
foreach my $underlay ('basewiki', reverse @{$config{underlaydirs}}) {
|
add_underlay("locale/$config{po_master_language}{code}/$underlay");
|
||||||
add_underlay("locale/".$config{po_master_language}{code}."/".$underlay);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -377,22 +390,26 @@ sub change (@) {
|
||||||
my $updated_po_files=0;
|
my $updated_po_files=0;
|
||||||
|
|
||||||
# Refresh/create POT and PO files as needed.
|
# Refresh/create POT and PO files as needed.
|
||||||
|
# (But avoid doing so if they are in an underlay directory.)
|
||||||
foreach my $file (grep {istranslatablefile($_)} @rendered) {
|
foreach my $file (grep {istranslatablefile($_)} @rendered) {
|
||||||
my $page=pagename($file);
|
|
||||||
my $masterfile=srcfile($file);
|
my $masterfile=srcfile($file);
|
||||||
|
my $page=pagename($file);
|
||||||
my $updated_pot_file=0;
|
my $updated_pot_file=0;
|
||||||
# Only refresh Pot file if it does not exist, or if
|
# Only refresh POT file if it does not exist, or if
|
||||||
# $pagesources{$page} was changed: don't if only the HTML was
|
# $pagesources{$page} was changed: don't if only the HTML was
|
||||||
# refreshed, e.g. because of a dependency.
|
# refreshed, e.g. because of a dependency.
|
||||||
if ((grep { $_ eq $pagesources{$page} } @origneedsbuild)
|
if ($masterfile eq "$config{srcdir}/$file" &&
|
||||||
|| ! -e potfile($masterfile)) {
|
((grep { $_ eq $pagesources{$page} } @origneedsbuild)
|
||||||
|
|| ! -e potfile($masterfile))) {
|
||||||
refreshpot($masterfile);
|
refreshpot($masterfile);
|
||||||
$updated_pot_file=1;
|
$updated_pot_file=1;
|
||||||
}
|
}
|
||||||
my @pofiles;
|
my @pofiles;
|
||||||
map {
|
foreach my $po (pofiles($masterfile)) {
|
||||||
push @pofiles, $_ if ($updated_pot_file || ! -e $_);
|
next if ! $updated_pot_file && ! -e $po;
|
||||||
} (pofiles($masterfile));
|
next if grep { $po=~/\Q$_\E/ } @{$config{underlaydirs}};
|
||||||
|
push @pofiles, $po;
|
||||||
|
}
|
||||||
if (@pofiles) {
|
if (@pofiles) {
|
||||||
refreshpofiles($masterfile, @pofiles);
|
refreshpofiles($masterfile, @pofiles);
|
||||||
map { IkiWiki::rcs_add($_) } @pofiles if $config{rcs};
|
map { IkiWiki::rcs_add($_) } @pofiles if $config{rcs};
|
||||||
|
@ -666,7 +683,6 @@ sub istranslatablefile ($) {
|
||||||
my $type=pagetype($file);
|
my $type=pagetype($file);
|
||||||
return 0 if ! defined $type || $type eq 'po';
|
return 0 if ! defined $type || $type eq 'po';
|
||||||
return 0 if $file =~ /\.pot$/;
|
return 0 if $file =~ /\.pot$/;
|
||||||
return 0 unless -e "$config{srcdir}/$file"; # underlay dirs may be read-only
|
|
||||||
return 1 if pagespec_match(pagename($file), $config{po_translatable_pages});
|
return 1 if pagespec_match(pagename($file), $config{po_translatable_pages});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,7 +250,6 @@ once [[intrigeri]]'s `meta` branch is merged.
|
||||||
An integration branch, called `meta-po`, merges [[intrigeri]]'s `po`
|
An integration branch, called `meta-po`, merges [[intrigeri]]'s `po`
|
||||||
and `meta` branches, and thus has thise additional features.
|
and `meta` branches, and thus has thise additional features.
|
||||||
|
|
||||||
|
|
||||||
Language display order
|
Language display order
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
@ -260,38 +259,6 @@ order, as `po_slave_languages` is a hash. It would need to be converted
|
||||||
to an array to support this. (If twere done, twere best done quickly.)
|
to an array to support this. (If twere done, twere best done quickly.)
|
||||||
--[[Joey]]
|
--[[Joey]]
|
||||||
|
|
||||||
po files in underlay
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
I think this plugin doesn't yet allow po files to be present in an
|
|
||||||
underlay to translate files also from the underlay.
|
|
||||||
|
|
||||||
In `istranslatablefile`, it specifically checks that
|
|
||||||
the file is present in srcdir.
|
|
||||||
|
|
||||||
Problem with this is that it precludes using po to translate
|
|
||||||
the basewiki (work which is well under way for Danish BTW),
|
|
||||||
since the translated po files cannot really be used.
|
|
||||||
|
|
||||||
A further problem comes if one wants to use a non-English language as the
|
|
||||||
`po_master_language`. It would be good to get a translated
|
|
||||||
basewiki, taking po files from the underlay and using them as the primary
|
|
||||||
page sources, but this plugin doesn't yet support that.
|
|
||||||
|
|
||||||
And, maybe it shouldn't? A user would not expect to see a po file when
|
|
||||||
editing the index page of their wiki, just because they're using a
|
|
||||||
different language. Instead, we might want to build localized .mdwn files
|
|
||||||
for the basewiki, and then ikiwiki would just use that translated underlay.
|
|
||||||
The when the user edits index, they get a nice mdwn file to start from.
|
|
||||||
|
|
||||||
So, we seem to have two cases, in one po files from the underlay should be
|
|
||||||
used, in the other not. Hmm. Support both?
|
|
||||||
|
|
||||||
> Update -- I've written po2wiki, which can spit out translated underlays
|
|
||||||
> in markdown format, and made the po plugin enable use of such underlays
|
|
||||||
> when the master language is not `en`.
|
|
||||||
--[[Joey]]
|
|
||||||
|
|
||||||
Duplicate %links ?
|
Duplicate %links ?
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue