chiark / gitweb /
i18n: Source-level framework: call setlocale, provide __ and ___
[dgit.git] / Debian / Dgit / I18n.pm
diff --git a/Debian/Dgit/I18n.pm b/Debian/Dgit/I18n.pm
new file mode 100644 (file)
index 0000000..c6f9e16
--- /dev/null
@@ -0,0 +1,26 @@
+# -*- perl -*-
+
+package Debian::Dgit::I18n;
+
+# This module provides
+#    __       a function which is an alias for gettext
+#    ___      sprintf wrapper that gettexts the format
+#
+# In perl the sub `_' is a `superglobal', which means there
+# is only one of it in the whole program and every reference
+# is to the same one.  So it's not really useable in modules.
+# Hence __.
+
+use Locale::gettext;
+
+BEGIN {
+    use Exporter;
+    @ISA = qw(Exporter);
+    @EXPORT = qw(__ ___);
+}
+
+
+sub __ { gettext @_; }
+sub ___ { my $f = shift @_; sprintf +(gettext $f), @_; }
+
+1;