Index: lang-guess-ajax.php
===================================================================
--- lang-guess-ajax.php	(revision 22211)
+++ lang-guess-ajax.php	(working copy)
@@ -35,6 +35,7 @@
 	$is_home        = ( '/' == $uri );
 	$is_forums      = ( '/support/' == $uri || '/support/forums/' == $uri || '/documentation/' == $uri || '/documentation-test/' == $uri );
 	$is_download    = ( '/download/' == $uri );
+	$is_learn       = ( isset( $_SERVER['HTTP_REFERER'] ) && 'learn.wordpress.org' === parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_HOST ) );
 
 	if ( $is_download ) {
 		$locales_where = $wpdb->prepare( 'latest_release = %s', WP_CORE_LATEST_RELEASE );
@@ -62,6 +63,8 @@
 
 	if ( $is_forums ) {
 		$guesses = $guesser->guess_locales_subdomains_with_forums();
+	} elseif ( $is_learn ) {
+		$guesses = $guesser->guess_locales_names();
 	} else {
 		$guesses = $guesser->guess_locales_subdomains();
 	}
@@ -76,22 +79,36 @@
 		$anonymized_ip   = preg_replace( '!\.\d+$!', '.xxx', $_SERVER['REMOTE_ADDR'] );
 		$ip_country      = $guesser->get_country_by_ip();
 
-		echo json_encode( compact( 'language_header', 'anonymized_ip', 'ip_country', 'guesses', 'is_home', 'is_forums', 'is_download' ), JSON_PRETTY_PRINT );
+		echo json_encode( compact( 'language_header', 'anonymized_ip', 'ip_country', 'guesses', 'is_home', 'is_forums', 'is_download', 'is_learn' ), JSON_PRETTY_PRINT );
 		die();
 	}
 
 	// Check the referring site, and filter out that locale.
 	if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
-		$ref_site = parse_url( $_SERVER['HTTP_REFERER'],  PHP_URL_HOST );
-		$ref_site = rtrim( str_replace( 'wordpress.org', '', $ref_site ), '.' );
-		if ( $ref_site ) {
+		// The locale for Learn comes from the query parameter rather than the subdomain.
+		if ( $is_learn && isset( $_GET['locale'] ) ) {
+			$ref_locale = $_GET['locale'];
+			
 			$guesses = array_filter(
 				$guesses,
-				function( $guess ) use ( $ref_site ) {
-					return $guess['subdomain'] !== $ref_site;
+				function( $guess ) use ( $ref_locale ) {
+					return $guess['locale'] !== $ref_locale;
 				}
 			);
 			$guesses = array_values( $guesses );
+		} else {
+			$ref_site = parse_url( $_SERVER['HTTP_REFERER'],  PHP_URL_HOST );
+			$ref_site = rtrim( str_replace( 'wordpress.org', '', $ref_site ), '.' );
+
+			if ( $ref_site ) {
+				$guesses = array_filter(
+					$guesses,
+					function( $guess ) use ( $ref_site ) {
+						return $guess['subdomain'] !== $ref_site;
+					}
+				);
+				$guesses = array_values( $guesses );
+			}
 		}
 	}
 
@@ -98,6 +115,8 @@
 	if ( is_array( $guesses ) && ! empty( $guesses ) ) {
 		if ( $is_forums ) {
 			$string = translate_gp( 'WordPress support forums are also available in %s.', $guesses[0]['locale'] );
+		} elseif ( $is_learn ) {
+			$string = translate_gp( 'Learn WordPress is also available in %s.', $guesses[0]['locale'] );
 		} else {
 			$string = translate_gp( 'WordPress is also available in %s.', $guesses[0]['locale'] );
 		}
@@ -104,7 +123,10 @@
 
 		$translated = array();
 		foreach ( $guesses as $guess ) {
-			if ( isset( $guess['name'], $guess['subdomain'] ) ) {
+			if ( $is_learn ) {
+				$name = \GP_Locales::by_field( 'wp_locale', $guess['locale'] )->native_name;
+				$translated[] = "<a href='https://learn.wordpress.org/?locale={$guess['locale']}'>{$name}</a>";
+			} elseif ( isset( $guess['name'], $guess['subdomain'] ) ) {
 				$path = '/';
 				if ( $is_forums ) {
 					$path = '/support/';
