diff --git a/includes/locale.inc b/includes/locale.inc
index 7fb8d64..a23bd3b 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -286,6 +286,10 @@ function locale_language_from_url($languages) {
           // Remove protocol and add http:// so parse_url works
           $host = 'http://' . str_replace(array('http://', 'https://'), '', $language->domain);
           $host = parse_url($host, PHP_URL_HOST);
+          if ($port = parse_url('http://' . $_SERVER['HTTP_HOST'], PHP_URL_PORT)) {
+            $host .= ":$port";
+          }
+
           if ($_SERVER['HTTP_HOST'] == $host) {
             $language_url = $language->language;
             break;
