Skip Menu |

This queue is for tickets about the libintl-perl CPAN distribution.

Report information
The Basics
Id: 79461
Status: resolved
Priority: 0/
Queue: libintl-perl

People
Owner: Nobody in particular
Requestors: david [...] justatheory.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



CC: "David E. Wheeler" <david [...] justatheory.com>
Subject: [PATCH] Search File::ShareDir for LocaleData.
Date: Wed, 5 Sep 2012 11:48:28 -0700
To: bug-libintl-perl [...] rt.cpan.org
From: "David E. Wheeler" <david [...] justatheory.com>
From: "David E. Wheeler" <david@justatheory.com> This is the most recent Perl-specific shared file location, with support built into the standard installer tools. So it makes sense to use it here. --- Makefile.PL | 2 +- lib/Locale/TextDomain.pm | 46 +++++++++++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 341b77e..5688839 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -205,7 +205,7 @@ WriteMakefile ( AUTHOR => 'Guido Flohr <guido@imperia.net>', ) : (), ), - PREREQ_PM => { File::Spec => 0 }, + PREREQ_PM => { File::Spec => 0, File::ShareDir => 0 }, PL_FILES => {}, DIR => [$result == 0 ? ('gettext_xs') : ()], clean => { FILES => 'xs_disabled build_xs' } diff --git a/lib/Locale/TextDomain.pm b/lib/Locale/TextDomain.pm index f70162d..a962963 100755 --- a/lib/Locale/TextDomain.pm +++ b/lib/Locale/TextDomain.pm @@ -300,9 +300,12 @@ sub import # Remember that we still have to bind that textdomain to # a directory. unless (exists $bound_dirs{$textdomain}) { - @search_dirs = map $_ . '/LocaleData', @INC, @default_dirs - unless @search_dirs; - $bound_dirs{$textdomain} = [@search_dirs]; + require File::ShareDir; + $bound_dirs{$textdomain} = [ + @search_dirs || map { "$_/LocaleData" } + (eval { File::ShareDir::dist_dir($textdomain) } || ()), + @INC, @default_dirs + ]; } Locale::TextDomain->export_to_level (1, $package, @EXPORT); @@ -495,18 +498,26 @@ to search other directories prior to the default directories. Specifying a differnt search directory is called I<binding> a textdomain to a directory. -B<Locale::TextDomain> extends the default strategy by a Perl -specific approach. Unless told otherwise, it will look for a -directory F<LocaleData> in every component found in the standard -include path C<@INC> and check for a database containing the message -for your textdomain there. Example: If the path -F</usr/lib/perl/5.8.0/site_perl> is in your C<@INC>, you can -install your translation files in F</usr/lib/perl/5.8.0/site_perl/LocaleData>, -and they will be found at run-time. +B<Locale::TextDomain> extends the default strategy by a Perl-specific +approach. Unless told otherwise, it will first look for a directory named +F<LocaleData> inin the directory returned by +C<File::ShareDir::dist_dir($textdomain)>, and check for a database containing +the message for your textdomain there. This allows you to install your +database in the Perl-specific shared directory using L<Module::Install>'s +C<install_share> directive or the Dist::Zilla L<ShareDir +plugin|Dist::Zilla::Plugin::ShareDir>. + +If it fails to find the translation files in the L<File::ShareDir> directory, +Locale::TextDomain will next look in every directory found in the standard +include path C<@INC>, and check for a database containing the message for your +textdomain there. Example: If the path F</usr/lib/perl/5.8.0/site_perl> is in +your C<@INC>, you can install your translation files in +F</usr/lib/perl/5.8.0/site_perl/LocaleData>, and they will be found at +run-time. =head1 USAGE -It is crucial to remember that you use Locale::TextDoamin(3) as +It is crucial to remember that you use Locale::TextDomain(3) as specified in the section L</SYNOPSIS>, that means you have to B<use> it, not B<require> it. The module behaves quite differently compared to other modules. @@ -519,7 +530,7 @@ as an argument to the use() function. It actually works like this: The first argument (the first string passed to use()) is the textdomain of your package, optionally followed by a list of directories to search I<instead> of the Perl-specific directories (see above: F</LocaleData> -appended to every part of C<@INC>). +appended to a F<File::ShareDir> directory and every path in C<@INC>). If you are the author of a package 'barfoos', you will probably put the line @@ -535,10 +546,11 @@ your module has been installed properly, including the message catalogs, it will then be able to retrieve these translations at run-time. If you have not installed the translation database in a directory -F<LocaleData> in the standard include path C<@INC> (or in the system -directories F</usr/share/locale> resp. F</usr/local/share/locale>), you -have to explicitely specify a search path by giving the names of -directories (as strings!) as additional arguments to use(): +F<LocaleData> in the L<File::ShareDir> directory or the standard include +path C<@INC> (or in the system directories F</usr/share/locale> resp. +F</usr/local/share/locale>), you have to explicitely specify a search +path by giving the names of directories (as strings!) as additional +arguments to use(): use Locale::TextDomain qw (barfoos ./dir1 ./dir2); -- 1.7.10
BTW, I generated this patch from the GitPan repository, but I see in RT#78341 that you do have a Git repo for libintl-perl. Is it publicly cloneable? If so, I will generate a new patch against the latest code (or send a pull request, as appropriate). Thanks! David
There's a typo in this patch. You said "inin" when you meant "in".
On 2012-09-09 13:56:38, CJM wrote: Show quoted text
> There's a typo in this patch. You said "inin" when you meant "in".
Oops, thanks for the catch! Guido, I will happily submit another patch with that fixed. Would love to clone your Git repo to produce a proper patch, though. David
FYI, I've cloned the Git repository and am now pushing my changes to my Clone on GitHub: https://github.com/theory/libintl-perl/tree/sharedir Best, David
Ping! Any chance of a release with this change soon? Thanks! David
Subject: Re: [rt.cpan.org #79461] [PATCH] Search File::ShareDir for LocaleData.
Date: Wed, 09 Jan 2013 12:47:58 +0100
To: "bug-libintl-perl [...] rt.cpan.org" <bug-libintl-perl [...] rt.cpan.org>
From: Guido Flohr <guido.flohr [...] imperia.bg>
On Tue, 2013-01-08 at 22:31 +0000, David Wheeler via RT wrote: Show quoted text
> Queue: libintl-perl > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79461 > > > Ping!
pong ;) Show quoted text
> Any chance of a release with this change soon?
I'll try to make a release until next Wednesday, okay? Cheers, Guido -- Империя ООД | Imperia OOD ул. „Княз-Борис-I“ № 86, София 1000 | ul. "Knyaz-Boris-I" № 86, Sofia http://www.imperia.bg/
Subject: Re: [rt.cpan.org #79461] [PATCH] Search File::ShareDir for LocaleData.
Date: Wed, 9 Jan 2013 09:19:49 -0800
To: bug-libintl-perl [...] rt.cpan.org
From: "David E. Wheeler" <david [...] justatheory.com>
On Jan 9, 2013, at 3:48 AM, "Guido Flohr via RT" <bug-libintl-perl@rt.cpan.org> wrote: Show quoted text
> I'll try to make a release until next Wednesday, okay?
Awesome, thanks! David
Fixed in git.