PHPackages                             spacemonk/craft-language-manager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. spacemonk/craft-language-manager

ActiveCraft-plugin[Localization &amp; i18n](/categories/localization)

spacemonk/craft-language-manager
================================

This plugin adds a language navigation and correct hreflang header attributes for multi language sites

1.1.1(1y ago)1399proprietaryPHP

Since Nov 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/spacemonkxyz/craft-language-manager)[ Packagist](https://packagist.org/packages/spacemonk/craft-language-manager)[ RSS](/packages/spacemonk-craft-language-manager/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

Language Manager for Craft CMS
==============================

[](#language-manager-for-craft-cms)

The Language Manager plugin adds easy integration for a language switcher and for the correct hreflang attributes in the header.

- The [language switcher](#language-switcher) is a simple menu that links to all parallel language versions of the same page
- The [hreflang tags](#hreflang-tags) add the correct hreflang attributes in the header of the page (including setting the `x-default` tag for the primary version)

Requirements
------------

[](#requirements)

This plugin requires Craft CMS 4.0 or later.

Installation
------------

[](#installation)

You can install this plugin from the plugin Store or with Composer.

#### From the Plugin Store

[](#from-the-plugin-store)

Go to the Plugin Store in your project’s Control Panel and search for “Language Manager”. Then press Install in its modal window.

#### With Composer

[](#with-composer)

Open your terminal and run the following commands:

```
# go to the project directory
cd /path/to/my-project

# tell Composer to load the plugin
composer require spacemonk/language-manager

# tell Craft to install the plugin
php craft plugin/install language-manager
```

Language Switcher
-----------------

[](#language-switcher)

The sites have to be added in the same site group in Craft CMS.

The language switcher will switch to the parallel site in a different language, if there is no parallel site, it will fall back to the main page. The labels can be set to [different styles or you can provide your own](#labels). The plugin supports keeping query parameters for the url (default `off`)

#### Easy → via hook

[](#easy--via-hook)

In your twig template at the position where you want to have the language switcher menu, add the following hook:

```
{% hook 'languageManagerNavigation' %}
```

You can also use caching (be careful when using cache together with the activated setting to keep query parameters).

```
{% cache %}
    {% hook 'languageManagerNavigation' %}
{% endcache %}
```

The main nav has the class `language-manager` for easy CSS targeting.

The output will look like this:

```

        English

        German

```

#### Advanced → custom integration

[](#advanced--custom-integration)

The plugin exposes a twig function `getLanguageManagerPages()`, which returns an array of page objects. [For details see below](#twig-function).

As a starting point you can copy the code from [the hook template here](https://github.com/spacemonkxyz/craft-language-manager/tree/main/src/templates/_frontend/language-navigation.twig).

### Labels

[](#labels)

You can choose from several options to display the language switcher labels.

1. Language Code (e.g. 'EN')
2. Long Language Code (e.g. 'EN-US')
3. Language Name (e.g. 'English')
4. Long Language Name (e.g. 'English (United States)')
5. Your own custom label translations, [see here](#custom-label-translations)

Hreflang Tags
-------------

[](#hreflang-tags)

#### Easy → via hook

[](#easy--via-hook-1)

In your template (in the html head), add the following hook:

```
{% hook 'languageManagerHreflang' %}
```

You can also use caching.

```
{% cache %}
    {% hook 'languageManagerHreflang' %}
{% endcache %}
```

The output will look like this:

```

```

The `x-default` attribute is set to the primary site.

#### Advanced → custom integration

[](#advanced--custom-integration-1)

The plugin exposes a twig function `getLanguageManagerPages()`, which returns an array of page objects. [For details see below](#twig-function).

As a starting point you can copy the code from [the hook template here](https://github.com/spacemonkxyz/craft-language-manager/tree/main/src/templates/_frontend/hreflang.twig).

Custom Label Translations
-------------------------

[](#custom-label-translations)

If you choose to provide your own label names, you can do so via the translations. The plugin uses the language codes (e.g. `en` or `en-US`) as translation key for the labels. To add your labels create a translation file with the name `language-manager.php` and place it in the folder with the specified language (e.g. `yourprojectroot/translations/en/language-manager.php`. Then add your translations:

```
