# HG changeset patch
# Node ID ba7ec8152cf9
# Parent  58d65c434a61
diff --git a/hasl/haslcontext.c b/hasl/haslcontext.c
--- a/hasl/haslcontext.c
+++ b/hasl/haslcontext.c
@@ -15,6 +15,8 @@
  * License along with this library; if not, see <https://www.gnu.org/licenses/>.
  */
 
+#include <glib/gi18n-lib.h>
+
 #include "haslcontext.h"
 
 #include "haslmechanismexternal.h"
@@ -522,7 +524,7 @@
 
 	if(!HASL_IS_MECHANISM(ctx->current_mechanism)) {
 		g_set_error(error, HASL_CONTEXT_DOMAIN, 0,
- 		            "current mechanism is NULL");
+		            _("current mechanism is NULL"));
 
 		return HASL_MECHANISM_RESULT_ERROR;
 	}
diff --git a/hasl/haslmechanismplain.c b/hasl/haslmechanismplain.c
--- a/hasl/haslmechanismplain.c
+++ b/hasl/haslmechanismplain.c
@@ -15,6 +15,8 @@
  * License along with this library; if not, see <https://www.gnu.org/licenses/>.
  */
 
+#include <glib/gi18n-lib.h>
+
 #include "haslmechanismplain.h"
 
 #include "haslcore.h"
@@ -38,7 +40,7 @@
 	value = hasl_context_get_username(context);
 	if(value == NULL || value[0] == '\0') {
 		g_set_error(error, HASL_MECHANISM_PLAIN_DOMAIN, 0,
-		            "missing username");
+		            _("missing username"));
 
 		return FALSE;
 	}
@@ -46,7 +48,7 @@
 	value = hasl_context_get_password(context);
 	if(value == NULL || value[0] == '\0') {
 		g_set_error(error, HASL_MECHANISM_PLAIN_DOMAIN, 0,
-		            "missing password");
+		            _("missing password"));
 
 		return FALSE;
 	}
@@ -54,7 +56,7 @@
 	if(!hasl_context_get_allow_clear_text(context)) {
 		if(!hasl_context_get_tls(context)) {
 			g_set_error(error, HASL_MECHANISM_PLAIN_DOMAIN, 0,
-			            "plain text is not allowed without TLS");
+			            _("plain text is not allowed without TLS"));
 
 			return FALSE;
 		}
@@ -81,14 +83,14 @@
 
 	username = hasl_context_get_username(ctx);
 	if(username == NULL || username[0] == '\0') {
-		g_set_error(error, HASL_DOMAIN, 0, "no username provided");
+		g_set_error(error, HASL_DOMAIN, 0, _("no username provided"));
 
 		return HASL_MECHANISM_RESULT_ERROR;
 	}
 
 	password = hasl_context_get_password(ctx);
 	if(password == NULL || password[0] == '\0') {
-		g_set_error(error, HASL_DOMAIN, 0, "no password provided");
+		g_set_error(error, HASL_DOMAIN, 0, _("no password provided"));
 
 		return HASL_MECHANISM_RESULT_ERROR;
 	}
diff --git a/meson.build b/meson.build
--- a/meson.build
+++ b/meson.build
@@ -36,6 +36,15 @@
 gobject = dependency('gobject-2.0', version : '>= 2.70')
 
 ###############################################################################
+# NLS
+###############################################################################
+GETTEXT_PACKAGE = 'hasl'
+LOCALE_DIR = get_option('prefix') / get_option('localedir')
+
+add_project_arguments(f'-DLOCALEDIR="@LOCALE_DIR@"', language : 'c')
+add_project_arguments(f'-DGETTEXT_PACKAGE="@GETTEXT_PACKAGE@"', language : 'c')
+
+###############################################################################
 # Documentation
 ###############################################################################
 if get_option('doc') and not get_option('introspection')
@@ -61,6 +70,7 @@
 # Sub-directories
 ###############################################################################
 subdir('hasl')
+subdir('po')
 
 # This needs to be after all of the sub-directories have been processed.
 if get_option('doc')
diff --git a/meson_options.txt b/meson_options.txt
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -9,3 +9,9 @@
   type : 'boolean', value : true, yield : true,
   description : 'Whether or not to build a GObject Introspection type library'
 )
+
+option(
+    'nls',
+    type : 'boolean', value : true, yield : true,
+    description : 'Install translation files'
+)
diff --git a/po/LINGUAS b/po/LINGUAS
new file mode 100644
diff --git a/po/POTFILES b/po/POTFILES
new file mode 100644
--- /dev/null
+++ b/po/POTFILES
@@ -0,0 +1,9 @@
+hasl/haslcontext.c
+hasl/haslmechanism.c
+hasl/haslmechanismexternal.c
+hasl/haslmechanismplain.c
+hasl/tests/test-context.c
+hasl/tests/test-full.c
+hasl/tests/test-mechanism.c
+hasl/tests/test-mechanism-external.c
+hasl/tests/test-mechanism-plain.c
diff --git a/po/meson.build b/po/meson.build
new file mode 100644
--- /dev/null
+++ b/po/meson.build
@@ -0,0 +1,12 @@
+if not get_option('nls')
+	summary('translations',
+		'You have disabled installation of translations which means ' +
+		'English will be the only available language.',
+		section : 'Warnings')
+
+	subdir_done()
+endif
+
+i18n = import('i18n')
+
+i18n.gettext(GETTEXT_PACKAGE, preset: 'glib')
diff --git a/po/update-potfiles.sh b/po/update-potfiles.sh
new file mode 100755
--- /dev/null
+++ b/po/update-potfiles.sh
@@ -0,0 +1,11 @@
+#!/bin/sh -e
+
+# make sure we're in the directory that contains this file.
+PARENT=$(dirname "${0}")
+cd "${PARENT}"
+
+# Find all of the source files in the library directory, get their path
+# relative to the parent directory of this file, sort them all, and then write
+# them to POTFILES and output to stdout.
+find ../hasl -iname "*.c" -exec realpath --relative-to .. {} \; | sort | tee POTFILES
+
