3

I have a site with 90% content in Chinese, and only 10% in English.

Thus the requirement of the client is that when viewing an article in English, everything around it remains in Chinese. Blocks, menus etc

a) Enable language prefix

What this does is sets english article with en/[node:title] which is acceptable. But the problem occurs as it appends that to every url in the menu, and other places. So they become like en/categories/CHINESE-CHARACTERS which is not right, and no content is displayed.

In pathauto for English articles, I thus tried, specifically giving it [node:title]. Yet it prepends the en.

b) Disable language prefix.

Now all my links are fine. But the english article is now a node/[nid]. The url aliases just don't seem to be working in this case. If I could just have the URL alias working in this case, things would be great too.

Any solution to my misery is welcome.

4 Answers 4

2

Aliases indeed disappear from nodes with non-default language after disabling language prefix in URLs. The solution to that is easy, but you have to do it in code, using Pathauto's hook_pathauto_alias_alter().

Basically all you need to do is:

function yourcustommodule_pathauto_alias_alter(&$alias, array &$context) {
  // Force all aliases to be saved as language neutral.
  $context['language'] = LANGUAGE_NONE;
}

This way you make sure that the language of the saved alias (not of node!) will always be und, meaning it will show for nodes of all languages.

Note: For existing aliases it is not enough to re-save the node. You have to delete the alias first and then have it recreated. Often the easiest is to do it in bulk via Pathauto's configuration interface. First delete all paths, then bulk-recreate them.

For more, see https://www.drupal.org/node/1234924

1
  • 1
    For Drupal 8 it is $context['language'] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
    – chap
    Commented Aug 6, 2018 at 6:23
1

this is an old question, but for future readers I recommend take a look to Pathauto i18n module. From the module page:

As you know by default Pathauto creates alias only for one language or for all languages one alias. This module provides functionality to create aliases for each language. Also this module will be helpful, if you use field translation and you want show node on all language with paths, different from node/nid.

Example

When you create node without pathauto_i18n: English alias: en/articles/first_article Italiano alias: not exist Deutsche alias: not exist

When you create node with pathauto_i18n: English alias: en/articles/first_article Italiano alias: it/articolo/first_article Deutsche alias: de/artikel/first_article

The same for taxonomy and users.

This module contains 3 submodules pathauto_i18n_node, pathauto_i18n_user and pathauto_i18n_taxonomy which allows enable separate functionality for each entity.

How to use

  • Enable multilingual support for nodes(needs only for nodes)
  • Configure alias patterns on page admin/config/search/path/patterns
  • Create entity with option "Generate automatic URL alias for other languages"

enter image description here

0

Try the Pathauto Persistent State module. Details from project page:

Pathauto tries to do it's best to remember if it should be allowed to continue automatically alias a node, but in some cases it needs some help to really remember if you clicked the 'Automatic alias' checkbox or not. So let's save that into the database!

Looks like pathauto as it is has problems dealing with multilingual settings. The module prevents it from "forgetting" these settings.

1
  • 1
    Apparently, except for one language (usually default) all the other links, need to have a language prefix on the url. You can't differentiate on the basis of just [node:title]. Atleast that's how pathauto works. Commented Apr 19, 2014 at 14:36
-1

Try neutral_paths www.drupal.org/project/neutral_paths

2
  • 1
    Can you give a little more detail? While this might answer the question, link-only answers can be vague and might not help someone why they can use this module.
    – Shawn Conn
    Commented Sep 13, 2016 at 21:57
  • this module works! Commented Sep 15, 2017 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.