]> git.openstreetmap.org Git - rails.git/commitdiff
Fix styling of email notifications in RTL languages
authorTom Hughes <tom@compton.nu>
Wed, 3 Jul 2019 08:49:46 +0000 (09:49 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 3 Jul 2019 08:49:46 +0000 (09:49 +0100)
Fixes #2297

app/helpers/notifier_helper.rb
app/views/layouts/notifier.html.erb
app/views/notifier/_message_body.html.erb

index 1c2e5e65437b18370f9d05f9a79313d846f4dd50..cc99898aa7b78ebe8e8121aec7e3aceaa86979bf 100644 (file)
@@ -32,4 +32,12 @@ module NotifierHelper
     # we apply it once here, after the message has been composed.
     html.gsub(/<p>/, '<p style="color: black; margin: 0.75em 0; font-family: \'Helvetica Neue\', Arial, Sans-Serif">')
   end
+
+  def style_left
+    I18n.t("html.dir") == "ltr" ? "left" : "right"
+  end
+
+  def style_right
+    I18n.t("html.dir") == "ltr" ? "right" : "left"
+  end
 end
index 21b4e35ceb95a65cfb7910968ccaf6093a822461..a5a8420f0fc25ab543259978e45dc57cae8f3e31 100644 (file)
@@ -1,4 +1,4 @@
-<html>
+<html lang="<%= I18n.locale %>" dir="<%= I18n.t("html.dir") %>">
   <head>
     <meta charset="UTF-8"></meta>
   </head>
@@ -8,7 +8,7 @@
         <%# having width=100% on the table and then only a fixed width on the middle cell gives us a max-width that works in Outlook %>
         <td rowspan="2"></td>
         <td width="600" style="text-align: center; padding: 0px 7px">
-          <table style="width: 100%; color: #222; margin-left: auto; margin-right: auto">
+          <table style="width: 100%; color: #222; margin-<%= style_left %>: auto; margin-<%= style_right %>: auto">
             <tr>
               <td style="width: 30px; padding: 10px 10px 10px 0px">
                 <a href="<%= @root_url %>" target="_blank">
                 </a>
               </td>
               <%# the "width: 100%" here looks wrong, but I couldn't find a better way of making Outlook give this cell full width %>
-              <td style="width: 100%; padding: 0px; text-align: left">
+              <td style="width: 100%; padding: 0px; text-align: <%= style_left %>">
                 <%# NB we need "text-decoration: none" twice: GMail only honours it on the <a> but Outlook only on the <strong> %>
                 <a href="<%= @root_url %>" target="_blank" style="text-decoration: none; color: #000">
-                  <strong style="text-decoration: none; font-size: 18px; font-weight: 600; margin: 0; text-align: left; font-family: 'Helvetica Neue', Arial, sans-serif">OpenStreetMap</strong>
+                  <strong style="text-decoration: none; font-size: 18px; font-weight: 600; margin: 0; text-align: <%= style_left %>; font-family: 'Helvetica Neue', Arial, sans-serif">OpenStreetMap</strong>
                 </a>
               </td>
             </tr>
@@ -27,7 +27,7 @@
               <td colspan="2">
                 <table style="background-color: #fff; color: #222; border: solid 1px #ccc; border-collapse: separate">
                   <tr>
-                    <td style="text-align: left; padding: 0px 15px 5px 15px">
+                    <td style="text-align: <%= style_left %>; padding: 0px 15px 5px 15px">
                       <%= raw style_message(yield) %>
                     </td>
                   </tr>
index f8a4e262127b06f86ba801bffa2ba801933ffd10..d572fb9d0a79e92e7486b56218d63792295b0116 100644 (file)
@@ -14,7 +14,7 @@
             :target => "_blank", :rel => "noopener"
           ) %>
     </td>
-    <td style="text-align: left; vertical-align: top; padding-right: 10px; width: 100%">
+    <td style="text-align: <%= style_left %>; vertical-align: top; padding-<%= style_right %>: 10px; width: 100%">
       <%= body %>
     </td>
   </tr>