From 6a9e16374f1549c7e63c7cd1c0e6989b2fb32191 Mon Sep 17 00:00:00 2001 From: joey Date: Sat, 29 Jul 2006 21:04:31 +0000 Subject: * 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. --- IkiWiki.pm | 12 +++++ IkiWiki/Rcs/svn.pm | 22 +++++++++ debian/changelog | 10 +++- doc/ikiwiki.setup | 2 + doc/patchqueue/locale_patch.mdwn | 102 --------------------------------------- 5 files changed, 44 insertions(+), 104 deletions(-) delete mode 100644 doc/patchqueue/locale_patch.mdwn diff --git a/IkiWiki.pm b/IkiWiki.pm index 2b877a370..085953a17 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -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})); diff --git a/IkiWiki/Rcs/svn.pm b/IkiWiki/Rcs/svn.pm index b5f5fb445..f01735afe 100644 --- a/IkiWiki/Rcs/svn.pm +++ b/IkiWiki/Rcs/svn.pm @@ -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; diff --git a/debian/changelog b/debian/changelog index 6ee1e7b14..6c07212fe 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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. - - -- Joey Hess Sat, 29 Jul 2006 16:43:50 -0400 + * 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 Sat, 29 Jul 2006 16:56:26 -0400 ikiwiki (1.12) unstable; urgency=low diff --git a/doc/ikiwiki.setup b/doc/ikiwiki.setup index 9310a4556..ca230f7b0 100644 --- a/doc/ikiwiki.setup +++ b/doc/ikiwiki.setup @@ -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 diff --git a/doc/patchqueue/locale_patch.mdwn b/doc/patchqueue/locale_patch.mdwn deleted file mode 100644 index 78e82f9ac..000000000 --- a/doc/patchqueue/locale_patch.mdwn +++ /dev/null @@ -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 \ No newline at end of file -- cgit v1.2.3