# polylang/trunk/src/Switcher/Layout/Nav.php

Polylang, version trunk. 62 lines.

- Page: https://pluginprobe.com/plugins/polylang/trunk/code/src/Switcher/Layout/Nav.php
- Raw: https://pluginprobe.com/plugins/polylang/trunk/raw/src/Switcher/Layout/Nav.php
- Modified: 2026-09-14T16:30:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/polylang/trunk/code/src/Switcher/Layout/Nav.php#L10-L20`.

```php
<?php
/**
 * @package Polylang
 */

namespace WP_Syntex\Polylang\Switcher\Layout;

use PLL_Language;
use WP_Syntex\Polylang\Switcher\Element\Nav as Element;

defined( 'ABSPATH' ) || exit;

/**
 * Class that displays a language switcher as a list.
 *
 * @since 3.9
 */
class Nav extends Abstract_Layout {
	/**
	 * Returns the markup of the switcher.
	 *
	 * @since 3.9
	 *
	 * @return string
	 */
	public function get(): string {
		$out = '';

		foreach ( $this->get_elements() as $element ) {
			$out .= $element->get();
		}

		if ( empty( $out ) || ! $this->settings->show_wrapper ) {
			return $out;
		}

		$cr  = $this->settings->preserve_spacing ? "\n" : '';
		$out = sprintf(
			'<%1$s id="%2$s" class="%3$s" aria-label="%4$s">%5$s</%1$s>',
			$this->get_nav_tag(),
			esc_attr( $this->settings->unique_id ),
			esc_attr( implode( ' ', $this->get_wrapper_classes() ) ),
			esc_attr( __( 'Choose a language', 'polylang' ) ),
			"{$cr}<ul>{$cr}{$out}</ul>"
		);

		return "{$cr}{$out}{$cr}";
	}

	/**
	 * Returns an instance of `Element\Nav`.
	 *
	 * @since 3.9
	 *
	 * @param PLL_Language $language Instance of `PLL_Language`.
	 * @return Element
	 */
	protected function get_element( PLL_Language $language ): Element {
		return new Element( $language, $this->settings, $this->links );
	}
}

```
