diff --git a/xmlsitemap.generate.inc b/xmlsitemap.generate.inc
index 57c3bc1..52a34ef 100644
--- a/xmlsitemap.generate.inc
+++ b/xmlsitemap.generate.inc
@@ -156,15 +156,16 @@ function xmlsitemap_generate_page(stdClass $sitemap, $page) {
 function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer, $chunk) {
   $output_elements = drupal_map_assoc(variable_get('xmlsitemap_output_elements', array('lastmod', 'changefreq', 'priority')));
   $lastmod_format = variable_get('xmlsitemap_lastmod_format', XMLSITEMAP_LASTMOD_MEDIUM);
+  $languages = language_list();
 
   $url_options = $sitemap->uri['options'];
   $url_options += array(
     'absolute' => TRUE,
     'base_url' => variable_get('xmlsitemap_base_url', $GLOBALS['base_url']),
-    'language' => language_default(),
+      // Get the language from the sitemap settings, if exists.
+    'language' => !empty($sitemap->context['language']) ? $languages[$sitemap->context['language']] : language_default(),
     'alias' => variable_get('xmlsitemap_prefetch_aliases', TRUE),
   );
-
   $last_url = '';
   $link_count = 0;
 
diff --git a/xmlsitemap.xmlsitemap.inc b/xmlsitemap.xmlsitemap.inc
index 3e23622..34a3329 100644
--- a/xmlsitemap.xmlsitemap.inc
+++ b/xmlsitemap.xmlsitemap.inc
@@ -57,11 +57,20 @@ class XMLSitemapWriter extends XMLWriter {
   }
 
   public function getSitemapUrl($path, array $options = array()) {
+
+    // Set an appropriate language to pass as an option to the url() call.
+    if (!empty($this->sitemap->context['language'])) {
+      $language = language_list()[$this->sitemap->context['language']];
+    }
+    else {
+      $language = language_default();
+    }
+
     $options += $this->sitemap->uri['options'];
     $options += array(
       'absolute' => TRUE,
       'base_url' => variable_get('xmlsitemap_base_url', $GLOBALS['base_url']),
-      'language' => language_default(),
+      'language' => $language,
       'alias' => TRUE,
     );
     if (!empty($options['protocol_relative'])) {
diff --git a/xmlsitemap_node/xmlsitemap_node.module b/xmlsitemap_node/xmlsitemap_node.module
index 3d0e534..11dba62 100644
--- a/xmlsitemap_node/xmlsitemap_node.module
+++ b/xmlsitemap_node/xmlsitemap_node.module
@@ -204,8 +204,8 @@ function xmlsitemap_node_create_link(stdClass $node) {
   $node->xmlsitemap['loc'] = $uri['path'];
   $node->xmlsitemap['lastmod'] = count($timestamps) ? max($timestamps) : 0;
   $node->xmlsitemap['access'] = $node->nid ? xmlsitemap_node_view_access($node, drupal_anonymous_user()) : 1;
-  $node->xmlsitemap['language'] = isset($node->language) ? $node->language : LANGUAGE_NONE;
-
+  $langcode = entity_language("node", $node);
+  $node->xmlsitemap['language'] = isset($langcode) ? $langcode : LANGUAGE_NONE;
   return $node->xmlsitemap;
 }
 
