Bug 26265: (QA follow-up) Remove g option from regex, add few dirs
[koha-equinox.git] / Koha / I18N.pm
index 44c4713..ca0ceae 100644 (file)
@@ -24,7 +24,9 @@ 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(:locale_h LC_MESSAGES);
+use POSIX qw( setlocale );
 use Koha::Cache::Memory::Lite;
 
 use parent 'Exporter';
@@ -54,8 +56,8 @@ sub init {
         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;
@@ -68,8 +70,8 @@ sub init {
                 $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);
@@ -175,7 +177,20 @@ sub N__np {
 }
 
 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 {