diff --git a/include/class.i18n.php b/include/class.i18n.php
index 2a28487eceb33507a550d86ffbd33de8cea79ac9..f412e5f9e2724448ad44360c5b5bbf1037fcc8ae 100644
--- a/include/class.i18n.php
+++ b/include/class.i18n.php
@@ -315,6 +315,15 @@ class Internationalization {
         return $best_match_langcode;
     }
 
+    static function getCurrentLanguage($user=false) {
+        global $thisstaff, $thisclient, $cfg;
+
+        $user = $user ?: $thisstaff ?: $thisclient;
+        if ($user && method_exists($user, 'getLanguage'))
+            return $user->getLanguage();
+        return Internationalization::getDefaultLanguage();
+    }
+
     static function bootstrap() {
 
         require_once INCLUDE_DIR . 'class.translation.php';
diff --git a/include/class.translation.php b/include/class.translation.php
index f4ee44662c75cc0f61279df3a44384fb839a48f1..b6fe18c2bf2293b520e417699d87e7ee9d94f746 100644
--- a/include/class.translation.php
+++ b/include/class.translation.php
@@ -708,10 +708,7 @@ class TextDomain {
     }
 
     static function configureForUser($user=false) {
-        if ($user && method_exists($user, 'getLanguage'))
-            $lang = $user->getLanguage();
-        else
-            $lang = Internationalization::getDefaultLanguage();
+        $lang = Internationalization::getCurrentLanguage($user);
 
         // Define locale for C-libraries
         putenv('LC_ALL=' . $lang);
diff --git a/include/client/header.inc.php b/include/client/header.inc.php
index 086ff99d8af06c40faae54336fbf9eb8b34aa633..efeffb5131d96afa59b921083c61fdfa408f2e42 100644
--- a/include/client/header.inc.php
+++ b/include/client/header.inc.php
@@ -8,7 +8,12 @@ $signout_url = ROOT_PATH . "logout.php?auth=".$ost->getLinkToken();
 header("Content-Type: text/html; charset=UTF-8\r\n");
 ?>
 <!DOCTYPE html>
-<html>
+<html <?php
+if (($lang = Internationalization::getCurrentLanguage())
+        && ($info = Internationalization::getLanguageInfo($lang))
+        && (@$info['direction'] == 'rtl'))
+    echo 'dir="rtl" class="rtl"';
+?>>
 <head>
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
diff --git a/include/staff/header.inc.php b/include/staff/header.inc.php
index 1185f2e1901529e115a0c4d07d34c55e80a22632..8754a29262c59b726f35e42cee17f3ed979979db 100644
--- a/include/staff/header.inc.php
+++ b/include/staff/header.inc.php
@@ -1,7 +1,7 @@
 <?php if (!isset($_SERVER['HTTP_X_PJAX'])) { ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html <?php
-if ($thisstaff && ($lang = $thisstaff->getLanguage())
+if (($lang = Internationalization::getCurrentLanguage())
         && ($info = Internationalization::getLanguageInfo($lang))
         && (@$info['direction'] == 'rtl'))
     echo 'dir="rtl" class="rtl"';