Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Facets 3.0.6 Minor update available for module facets (3.0.6). Release: Facets 3.0.5 Minor update available for module facets (3.0.5). Release: Flag 5.1.0 Minor update available for module flag (5.1.0). Release: Text with summary 1.0.0 Initial release available for module text_with_summary (1.0.0)! Release: Ágora Transparency Theme 1.0.7 Minor update available for theme agora_theme (1.0.7). Release: Automated Revision Log 1.1.3 Minor update available for module ai_revision_log (1.1.3). Release: Views HTTP Client 1.0.4 Minor update available for module views_http_client (1.0.4). Release: Block Layout Accordion 1.0.2 Minor update available for module block_layout_accordion (1.0.2). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Module Revived: ЮKassa (YooMoney) для Drupal v7 2.6.1 Module yoomoney_api updated after 7 months of inactivity (2.6.1).

This module allows websites to automatically detect a visitor's language and country based on the URL, using formats like `/en-ca` for English in Canada. It also supports browsing without a country prefix and provides a service to easily retrieve the current country code for other site functionalities.

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.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Nov 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Releases

Version Type Core Release date
1.0.0-alpha5 Pre-release 10–11 Mar 8, 2025
1.0.0-alpha4 Pre-release 10–11 Nov 11, 2024