Bug 25517: Look in all possible places for MO files
authorJulian Maurice <julian.maurice@biblibre.com>
Fri, 22 May 2020 14:45:02 +0000 (16:45 +0200)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Sat, 23 May 2020 07:31:21 +0000 (08:31 +0100)
On a 'dev' install, MO files will be installed in
<intranetdir>/misc/translator/po
On 'standard' and 'single' installs, they will be installed in
<intranetdir>/../../misc/translator/po

This patch makes Koha::I18N try to use the "dev" directory first, and
fallback to the "standard" directory.
If none of these directories exist, it dies.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/I18N.pm

index 7206223..ca0ceae 100644 (file)
@@ -24,6 +24,7 @@ use C4::Languages;
 use C4::Context;
 
 use Encode;
+use List::Util qw( first );
 use Locale::Messages qw(:locale_h LC_MESSAGES);
 use POSIX qw( setlocale );
 use Koha::Cache::Memory::Lite;
@@ -176,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 {