use Modern::Perl;
-use CGI;
use C4::Languages;
use C4::Context;
use Encode;
-use Locale::Messages qw(:locale_h nl_putenv setlocale LC_MESSAGES);
+use List::Util qw( first );
+use Locale::Messages qw(
+ bindtextdomain
+ gettext
+ LC_MESSAGES
+ ngettext
+ npgettext
+ pgettext
+ textdomain
+);
+use POSIX;
use Koha::Cache::Memory::Lite;
use parent 'Exporter';
if (@system_locales) {
# LANG needs to be set to a valid locale,
# otherwise LANGUAGE is ignored
- nl_putenv('LANG=' . $system_locales[0]);
- setlocale(LC_MESSAGES, '');
+ $ENV{LANG} = $system_locales[0];
+ POSIX::setlocale(LC_MESSAGES, '');
my $langtag = C4::Languages::getlanguage;
my @subtags = split /-/, $langtag;
$locale .= '_' . $region;
}
- nl_putenv("LANGUAGE=$locale");
- nl_putenv('OUTPUT_CHARSET=UTF-8');
+ $ENV{LANGUAGE} = $locale;
+ $ENV{OUTPUT_CHARSET} = 'UTF-8';
my $directory = _base_directory();
textdomain($textdomain);
}
sub _base_directory {
- return C4::Context->config('intranetdir') . '/misc/translator/po';
+ # Directory structure is not the same for dev and standard installs
+ # Here we test the existence of several directories and use the first that exist
+ # FIXME There has to be a better solution
+ my @dirs = (
+ C4::Context->config('intranetdir') . '/misc/translator/po',
+ C4::Context->config('intranetdir') . '/../../misc/translator/po',
+ );
+ my $dir = first { -d } @dirs;
+
+ unless ($dir) {
+ die "The PO directory has not been found. There is a problem in your Koha installation.";
+ }
+
+ return $dir;
}
sub _gettext {