Drupal is a registered trademark of Dries Buytaert

The Language-Country Negotiation module aims to provide language negotiation functionality in Drupal while also handling the current country of the visitor via a language-country path prefix.

What does this module do?

With the Language-Country Negotiation module, users can navigate your site using URLs such as:

example.com/{$LANGCODE}-{$COUNTRY_CODE}.

This approach informs the language manager of the current language and the current country service of the visitor's country code. For example:

  • example.com/en-ca (English in Canada)
  • example.com/fr-ca (French in Canada)
  • example.com/de-de (German in Germany)
  • example.com/en-gb (English in Great Britain)
  • example.com/en-kr (English in South Korea)

Additionally, users can access the site without a path prefix, entering an international state. In this mode, other negotiation methods such as URL (Path prefix) can come into play. This feature is particularly useful when implementing a country banner or allowing users to browse the website without specifying a country.

How to use?

  1. Installation: Start by installing the module via Composer.
  2. Add Languages: Go to Configuration > Region and language > Languages and add all required languages.
  3. Add Countries: Go to Configuration > Region and language > Countries and add countries with their available languages.
  4. Activation: Go to Configuration > Region and language > Languages > Detection and selection and activate the Language-country URL detection method.
  5. Configuration (Planned): Customize the detection method with prefix patterns and language codes. Optionally, enable negotiation for admin pages and strict negotiation (disallowing the international state).
  6. Fallbacks: Navigate to Configuration > Region and language > Languages > Language-country fallbacks_to activate convenient fallback methods for the path prefix and the path alias manager.
  7. Extend: Extend the country entities through fields to use in downstream business logic, e.g., tax label or indexation options.

Features

This module provides a lightweight implementation of a language negotiation plugin, with the following objectives:

  1. Current Country Service: Offers a streamlined CurrentCountry service that can be consumed by downstream logic, enabling easy retrieval of the current country code. Use as follows: $this->currentCountry->getCurrentCountryCode();
  2. Flexible Country Entities: Allows easy extension via fieldable country entities, which govern all language-country combinations.
  3. Configurable Language Per Country: Makes it possible to configure allowed languages per country, offering flexibility in content delivery.
  4. Enhanced Path Processing: Improves the end-user experience with adaptable path processing. The module includes a fallback path alias manager.
  5. Integration (Planned): Integrates with custom translation fallback chains for different countries based on the Entity Language Fallback module.

Language Switcher Block

If you intend to only display available languages in the core language switcher block you may need to employ the changes proposed in #3007386: Language negotiator weights should be changeable in settings.php. Please use the patch in comment #49.

Development Plan

Please note that this module is still in development, and several planned enhancements are in the pipeline before reaching a stable release. These include:

  1. Custom Entity for Countries: Implement a custom entity structure for representing countries. (Done)
  2. Country Switcher Block: Improve the country switcher block and its corresponding template. (Done)
  3. Plugin Configuration: Allow configuration options for the prefix pattern, exclusion of admin pages from negotiation, and enabling strict negotiation (disallowing the international state).
  4. Submodules: Create submodules to manage different fallback mechanisms.
  5. Integration: Connect with the Entity Language Fallback module.
  6. Access Policy Submodule: Provide a submodule with access policy features.

Similar projects

For similar functionality, you may explore the Domain module ecosystem. Additionally, you can achieve similar behavior with the Domain Country Path module.

Sponsored by Factorial GmbH

This project is sponsored by Factorial GmbH. Drop us a line if you are looking for interesting open source employment.

Activity

Total releases
1
First release
Mar 2025
Latest release
11 months ago
Release cadence
Stability
0% stable

Releases

Version Type Release date
1.0.0-alpha5 Pre-release Mar 8, 2025