Permalink
Browse files

Server-side component of email localisation

  • Loading branch information...
1 parent 99f82ec commit 73b7042d26657bceb809b7a22b2cbfeb07a26eae @birtles birtles committed Oct 19, 2012
View
@@ -9,9 +9,8 @@ require_once("parapara.inc");
function compileTemplate($file, $vars)
{
global $config;
- $file = $config['templates']['path'] . $file;
- // Check file exists and is readable
- if (!is_readable($file) || !is_file($file))
+ $file = getTemplateFile($file);
+ if (!$file)
return null;
// Setup environment
@@ -50,4 +49,12 @@ function compileEmailTemplate($file, $vars)
return array('subject' => $subject, 'body' => $body);
}
+function getTemplateFile($file)
+{
+ global $config;
+ $file = $config['templates']['path'] . $file;
+ // Check file exists and is readable
+ return is_readable($file) && is_file($file) ? $file : null;
+}
+
?>
@@ -65,8 +65,9 @@
$url = shortenUrl(getGalleryUrlForId($id));
// Make up email template
-// XXX Localize this too
-$template = compileEmailTemplate("email_anim.inc",
+$locale = trim(@$json["locale"]);
+$templateFile = getTemplateFileForLocale($locale);
+$template = compileEmailTemplate($templateFile,
array("url" => $url, "author" => $author, "title" => $title));
if (!$template) {
bailWithError('template-failed');
@@ -95,4 +96,14 @@
print "{}"; // Success, empty response
+function getTemplateFileForLocale($locale) {
+ $reLangCode = "/^([[:alpha:]]{1,8})(-[[:alpha:]]{1,8})?$/";
+ if ($locale && preg_match($reLangCode, $locale)) {
+ $test = "email_anim." . $locale . ".inc";
+ if (getTemplateFile($test))
+ return $test;
+ }
+ return "email_anim.en-US.inc";
+}
+
?>
@@ -0,0 +1,22 @@
+Subject: Parapara Animation
+<?php
+ if ($author) {
+ echo "Dear ".$author."\n";
+ }
+?>
+Thanks for making a Parapara Animation!
+
+You can visit see your creation at the link below.
+<?php echo $url; ?>
+
+
+Title: <?php echo $title; ?>
+
+Author: <?php echo $author ?>
+
+
+You can view your artwork at home. Why not show it to your family and friends!
+
+--
+Parapara Animation Team
+parapara@mozilla-japan.org

0 comments on commit 73b7042

Please sign in to comment.