From 723e4fbd260b84783860014927871a836c674cd8 Mon Sep 17 00:00:00 2001
From: Guillaume Rousse <guillaume.rousse@renater.fr>
Date: Fri, 7 Dec 2018 17:13:23 +0100
Subject: [PATCH] allow custom translation files

---
 bin/access-check-manager.cgi.in |  6 +++++-
 lib/AccountManager/App.pm       |  1 +
 lib/AccountManager/L10N.pm      | 15 +++++++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/bin/access-check-manager.cgi.in b/bin/access-check-manager.cgi.in
index 9cf8b59..bac9ef5 100755
--- a/bin/access-check-manager.cgi.in
+++ b/bin/access-check-manager.cgi.in
@@ -6,6 +6,7 @@ use utf8;
 use lib qw(@modulesdir@);
 
 use Config::Tiny;
+use File::Basename;
 
 use AccountManager::App;
 
@@ -16,8 +17,11 @@ if (!$configuration) {
     die Config::Tiny->errstr() . "\n";
 }
 
+my $configuration_directory = dirname($configuration_file);
+
 my $app = AccountManager::App->new(
-    configuration => $configuration
+    configuration => $configuration,
+    custom_l10n   => sprintf("%s/l10n", $configuration_directory)
 );
 $app->run();
 
diff --git a/lib/AccountManager/App.pm b/lib/AccountManager/App.pm
index f7af532..ff5f2d0 100644
--- a/lib/AccountManager/App.pm
+++ b/lib/AccountManager/App.pm
@@ -87,6 +87,7 @@ sub new {
             }
         );
     }
+    $self->{lh}->load_custom_lexicon($args{custom_l10n});
 
     if (!$self->{configuration}->{mailer}) {
         $self->{logger}->fatal(
diff --git a/lib/AccountManager/L10N.pm b/lib/AccountManager/L10N.pm
index 515c038..c8c17b4 100644
--- a/lib/AccountManager/L10N.pm
+++ b/lib/AccountManager/L10N.pm
@@ -4,5 +4,20 @@ use strict;
 use warnings;
 
 use base 'Locale::Maketext';
+use Locale::Maketext::Lexicon::Gettext;
+
+sub load_custom_lexicon {
+    my ($self, $directory) = @_;
+
+    my $language = $self->language_tag();
+
+    my $lexicon_file = sprintf("%s/%s.po", $directory , $language);
+    return unless -f $lexicon_file;
+
+    Locale::Maketext::Lexicon->import({
+        $language => [Gettext => $lexicon_file],
+        _decode => 1,
+    });
+}
 
 1;
-- 
GitLab