From: Steinar H. Gunderson
Date: Sun, 10 Jun 2012 01:24:22 +0000 (+0200)
Subject: Support translation of templates via po4a. Add an English translation as an example.
X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=0b296666f77d2431a26be5be4856499c5e0c2cd8;p=wloh
Support translation of templates via po4a. Add an English translation as an example.
---
diff --git a/include/common.pm b/include/common.pm
index 6ad6ae4..7ffaeee 100644
--- a/include/common.pm
+++ b/include/common.pm
@@ -35,6 +35,12 @@ sub get_locale {
return $1;
}
+sub set_locale {
+ my $locale = shift;
+ $locale =~ s/-/_/;
+ POSIX::setlocale(&POSIX::LC_ALL, $locale . '.UTF-8');
+}
+
sub get_auxillary_parameters {
my ($dbh, $locale) = @_;
@@ -106,10 +112,26 @@ sub print_navbar {
print "
\n";
}
+# mapping from locale to translation to use (if not found, "en" is used)
+my %translation_mapping = (
+ 'nb-NO' => 'no',
+ 'nn-NO' => 'no',
+ 'da-DK' => 'no',
+ 'sv-SE' => 'no',
+ 'nl-NL' => 'en',
+);
+
sub process_template {
- my ($filename, $parms) = @_;
+ my ($filename, $locale, $parms) = @_;
- my $doc = XML::Template::process_file('../templates/' . $filename, $parms);
+ my $translation = $translation_mapping{$locale} // 'en';
+ my $doc;
+ if (-r "../templates/$filename.$translation.xml") {
+ $parms->{'html/xml:lang'} = $translation;
+ $doc = XML::Template::process_file("../templates/$filename.$translation.xml", $parms);
+ } else {
+ $doc = XML::Template::process_file("../templates/$filename.xml", $parms);
+ }
print $doc->toString;
}
diff --git a/po/en.po b/po/en.po
new file mode 100644
index 0000000..2c84281
--- /dev/null
+++ b/po/en.po
@@ -0,0 +1,313 @@
+# SOME DESCRIPTIVE TITLE
+# Copyright (C) YEAR Free Software Foundation, Inc.
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR , YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2012-06-10 03:20+0300\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME \n"
+"Language-Team: LANGUAGE \n"
+"Language: en\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. type: Content of:
+#: templates/index.xml:7 templates/index.xml:31 templates/scenario.xml:7
+#: templates/scenario-not-found.xml:7
+#, no-wrap
+msgid "WLoH-plasseringsannsynlighetsberegning"
+msgstr "WLoH ranking probability calculation"
+
+#. type: Content of:
+#: templates/index.xml:33 templates/rating.xml:21
+#, no-wrap
+msgid ""
+"Dette er et hobbyprosjekt fra tredjepart, og ikke en offisiell del av\n"
+" "
+msgstr "This is a hobby project from a third party, and not an official part of "
+
+#. type: Content of: