* Locale patch from Faidon:

- Adds a locale setting to setup files.
  - Proper local time, if the locale configuration option is used.
  - Support for UTF-8 (or ISO-8859-X) filenames in SVN. Before this patch,
    commiting (or even rcs_updating) on repositories with UTF-8 filenames was
    impossible.
master
joey 2006-07-29 21:04:31 +00:00
parent 48f9d39339
commit 6a9e16374f
5 changed files with 43 additions and 103 deletions

View File

@ -49,9 +49,21 @@ sub defaultconfig () { #{{{
adminemail => undef,
plugin => [qw{mdwn inline htmlscrubber}],
timeformat => '%c',
locale => undef,
} #}}}
sub checkconfig () { #{{{
# locale stuff; avoid LC_ALL since it overrides everything
if (defined $ENV{LC_ALL}) {
$ENV{LANG} = $ENV{LC_ALL};
delete $ENV{LC_ALL};
}
if (defined $config{locale}) {
eval q{use POSIX};
$ENV{LANG} = $config{locale}
if POSIX::setlocale(&POSIX::LANG, $config{locale});
}
if ($config{w3mmode}) {
eval q{use Cwd q{abs_path}};
$config{srcdir}=possibly_foolish_untaint(abs_path($config{srcdir}));

View File

@ -4,11 +4,33 @@
use warnings;
use strict;
use IkiWiki;
use POSIX qw(setlocale LC_CTYPE);
package IkiWiki;
my $svn_webcommit=qr/^web commit (by (\w+)|from (\d+\.\d+\.\d+\.\d+)):?(.*)/;
# svn needs LC_CTYPE set to a UTF-8 locale, so try to find one. Any will do.
sub find_lc_ctype() {
my $current = setlocale(LC_CTYPE());
return $current if $current =~ m/UTF-?8$/i;
# Make some obvious attempts to avoid calling `locale -a`
foreach my $locale ("$current.UTF-8", "en_US.UTF-8", "en_GB.UTF-8") {
return $locale if setlocale(LC_CTYPE(), $locale);
}
# Try to get all available locales and pick the first UTF-8 one found.
if (my @locale = grep(/UTF-?8$/i, `locale -a`)) {
chomp @locale;
return $locale[0] if setlocale(LC_CTYPE(), $locale[0]);
}
# fallback to the current locale
return $current;
} # }}}
$ENV{LC_CTYPE} = $ENV{LC_CTYPE} || find_lc_ctype();
sub svn_info ($$) { #{{{
my $field=shift;
my $file=shift;

8
debian/changelog vendored
View File

@ -11,8 +11,14 @@ ikiwiki (1.13) UNRELEASED; urgency=low
when upgrading to get the cleanup globally.
* Polygen plugin from Enrico.
* htmltidy plugin from Faidon.
* Locale patch from Faidon:
- Adds a locale setting to setup files.
- Proper local time, if the locale configuration option is used.
- Support for UTF-8 (or ISO-8859-X) filenames in SVN. Before this patch,
commiting (or even rcs_updating) on repositories with UTF-8 filenames was
impossible.
-- Joey Hess <joeyh@debian.org> Sat, 29 Jul 2006 16:43:50 -0400
-- Joey Hess <joeyh@debian.org> Sat, 29 Jul 2006 16:56:26 -0400
ikiwiki (1.12) unstable; urgency=low

View File

@ -72,6 +72,8 @@ use IkiWiki::Setup::Standard {
#exclude => qr/\*.wav/,
# Time format (for strftime)
#timeformat => '%c',
# Locale to use. Must be a UTF-8 locale.
#locale => 'en_US.UTF-8',
# To add plugins, list them here.
#add_plugins => [qw{meta tag pagecount brokenlinks search smiley

View File

@ -1,102 +0,0 @@
This v2 patch is a different approach after Joey's comments and some though.
It achieves:
1. Proper local time, if the locale configuration option is used,
2. Support for UTF-8 (or ISO-8859-X) filenames in SVN. Before this
patch, commiting (or even rcs_updating) on repositories with UTF-8
filenames was impossible.
The svn backend sets `LC_CTYPE` to the following, in order of preference:
* The current locale, if it contains utf8/UTF-8,
* The current locale with the string ".UTF-8" appended to it,
* `en_US.UTF-8`/`en_GB.UTF-8` -- a bit hacky, but they're _very_ common and
they can help avoiding a call to `locale -a`, which may not be available
in the current system,
* The first UTF-8 locale it encounters from `locale -a`. Note that `LC_CTYPE`
is the same for every UTF-8 locale, so it doesn't matter which one will be used.
-- [[Faidon]]
----
Index: IkiWiki/Rcs/svn.pm
===================================================================
--- IkiWiki/Rcs/svn.pm (revision 967)
+++ IkiWiki/Rcs/svn.pm (working copy)
@@ -4,11 +4,35 @@
use warnings;
use strict;
use IkiWiki;
+use POSIX qw(setlocale LC_CTYPE);
package IkiWiki;
my $svn_webcommit=qr/^web commit (by (\w+)|from (\d+\.\d+\.\d+\.\d+)):?(.*)/;
+sub find_lc_ctype() {
+ my $current = setlocale(LC_CTYPE);
+
+ # Respect current locale if it's a UTF-8 one
+ return $current if $current =~ m/UTF-?8$/i;
+
+ # Make some obvious attempts to avoid calling `locale -a`
+ foreach my $locale ("$current.UTF-8", "en_US.UTF-8", "en_GB.UTF-8") {
+ return $locale if setlocale(LC_CTYPE, $locale);
+ }
+
+ # Try to get all available locales and pick the first UTF-8 one if found
+ if (my @locale = grep(/UTF-?8$/i, `locale -a`)) {
+ chomp @locale;
+ return $locale[0] if setlocale(LC_CTYPE, $locale[0]);
+ }
+
+ # fallback to the current locale
+ return $current;
+
+} # }}}
+$ENV{LC_CTYPE} = $ENV{LC_CTYPE} || find_lc_ctype();
+
sub svn_info ($$) { #{{{
my $field=shift;
my $file=shift;
Index: IkiWiki.pm
===================================================================
--- IkiWiki.pm (revision 967)
+++ IkiWiki.pm (working copy)
@@ -49,9 +49,21 @@
adminemail => undef,
plugin => [qw{mdwn inline htmlscrubber}],
timeformat => '%c',
+ locale => undef,
} #}}}
sub checkconfig () { #{{{
+ # locale stuff; avoid LC_ALL since it overrides everything
+ if (defined $ENV{LC_ALL}) {
+ $ENV{LANG} = $ENV{LC_ALL};
+ delete $ENV{LC_ALL};
+ }
+ if (defined $config{locale}) {
+ eval q{use POSIX};
+ $ENV{LANG} = $config{locale}
+ if POSIX::setlocale(&POSIX::LANG, $config{locale});
+ }
+
if ($config{w3mmode}) {
eval q{use Cwd q{abs_path}};
$config{srcdir}=possibly_foolish_untaint(abs_path($config{srcdir}));
Index: doc/ikiwiki.setup
===================================================================
--- doc/ikiwiki.setup (revision 967)
+++ doc/ikiwiki.setup (working copy)
@@ -72,6 +72,9 @@
#exclude => qr/\*.wav/,
# Time format (for strftime)
#timeformat => '%c',
+ # Locale to be used, useful for language customization of last-modified
+ # time. WARNING: Must be a UTF-8 locale!
+ #locale => 'en_US.UTF-8',
# To add plugins, list them here.
#add_plugins => [qw{meta tag pagecount brokenlinks search smiley