Steps to replicate the bug on a clean HEAD install:
- enable locale and translate modules (admin/build/modules)
- add a couple of new languages (admin/settings/language/add)
- set 'en' as the prefix for English (admin/settings/language/edit/en)
- select 'Path prefix only' as the 'Language negotiation' setting (admin/settings/language/configure)
- enable the language switcher block on (admin/build/block)

Now, I select a language other than English from the switcher block and browse around. All paths should be correctly prefixed with 'fr' or 'es'. Now switch back to English, browse around and note that there is no prefix.

One work around seems to be selecting the 'Path prefix with language fallback' setting for the 'Language negotiation' setting (admin/settings/language/configure). This results in correctly prefixed links.

CommentFileSizeAuthor
#1 language_244162.patch993 bytesdrewish
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drewish’s picture

Status: Active » Needs review
FileSize
993 bytes

I tracked the problem down to language_url_rewrite(). The value of $options['language'] is either specified by the user or assigned the global $language which is set by drupal_init_language(). If there is only a single language installed drupal_init_language() returns it, otherwise it calls language_initialize() which property distinguishes between the LANGUAGE_NEGOTIATION_PATH_DEFAULT and LANGUAGE_NEGOTIATION_PATH cases.

Considering that $options['language']->language is set appropriately I think the only thing to be concerned about is inserting a prefix if one exists. So it seems obvious that the two cases should be merged.

drewish’s picture

I just discovered:
#237140: Default language ignores Path prefix
which I duplicated but since I've got a patch I'll leave this one active.

ogi’s picture

subscribe

Dries’s picture

I'd like to see this patch reviewed by Gabor first. He is one of the main authors of the locale module.

link0ff’s picture

I think not including the default language prefix when 'Language negotiation' is set to 'Path prefix only' is a reasonable behavior. I guess the reason of adding special code in language.inc was because this prefix is not necessary when a page is displayed in the default language. This has a benefit of producing language-independent urls, so you can copy an url and send it to a friend in another country who will see this page in his/her preferred language.

So I think that language prefixes serve the single purpose to tell Drupal to display the current page in a non-default language, so a prefix is not necessary when the current page is displayed in the default language.

It seems that this behavior was implemented only for 'Path prefix only', and not for 'Path prefix with language fallback' because it doesn't work for the case where the default language is detected from the browser settings. But then this is a bug that should be fixed, so with the option 'Path prefix with language fallback' only a prefix equivalent to the browser's preferred language should be removed from url.

drewish’s picture

jurta, if you don't want the prefix for the default language you can simply remove it. the problem is if you do want the path prefix you're out of luck, you have to select 'Path prefix with language fallback' which offers different functionality.

This has a benefit of producing language-independent urls, so you can copy an url and send it to a friend in another country who will see this page in his/her preferred language.

that would be a totally separate feature and it doesn't work the way you described. the only time it would work is when you're viewing the page in the default language and send the link to someone else... if you're looking at /fr/* and send someone the link they'll see french by default no matter what the browser specifies.

link0ff’s picture

As an administrator, I can remove the prefix for the default language, but this is rather an user preference. So when deciding what is the best to do, it would be better to look at this problem from the user's point of view.

As an user, I see no problem to always add the path prefix, so I don't oppose the change you proposed. Adding the path prefix to all urls is not an unnatural thing for a multi-lingual site, so we always will get consistent urls.

What I'd rather ask is also to add the 'en' prefix to English by default. It cost me much time (this is how I reached these bug reports :-) to find why the language switcher doesn't work for non-English languages. It was absolutely not self-evident that this error was caused by English missing its prefix after I changed the default language to another language. And I see others have the same problem.

So please accompany your change that always adds a path prefix with the change that sets 'en' to English by default. Thanks.

drewish’s picture

jurta, there's an issue for that already: #146084: Default path prefix for English (and DBTNG it)

drewish’s picture

oh, i just realized that you've already commented on that ;)

link0ff’s picture

drewish, today Gábor already commented on the issue of setting a default path prefix 'en' for English. So let's wait another feedback from Gábor about your patch here that removes unnecessary code in language_url_rewrite(), so an existing path prefix will be inserted always, even for the default language. I see no problem in the behavior you propose because once a user's default language is determined on the first page visited without a path prefix, there is no need to repeat this using the language negotiation mechanism when the user navigates the same site using the default language. It seems safe to always keep this default language in the path prefix explicitly, with the assumption than the language switcher is always available for users to switch to another language.

link0ff’s picture

It seems some people prefer not to add a prefix path for the default language. Please see #208712: Option to not prefix paths with the default language that provides a patch with a new option for i18n in Drupal 5. Maybe the same option is necessary in Drupal 6/7?

Gábor Hojtsy’s picture

Ok, let's read the help text for "Path prefix only" (which is the name for LANGUAGE_NEGOTIATION_PATH_DEFAULT):

The presentation language is determined by examining the path for a language code or other custom string that matches the path prefix (if any) specified for each language. If a suitable prefix is not identified, the default language is used. Example: "example.com/de/contact" sets presentation language to German based on the use of "de" within the path.

So the prefix is matched and if not found, the default language is used. If you look at language_initialize(), this is what happens. For LANGUAGE_NEGOTIATION_PATH_DEFAULT and LANGUAGE_NEGOTIATION_PATH, the language is tried to be identified and it not possible and LANGUAGE_NEGOTIATION_PATH_DEFAULT is used, the default language is set (otherwise it falls back to other means of identifying the language).

Now when generating links, because the non-identifiable prefix leads to the default language being selected, if a link to a default language URL is to be generated, there is no language prefix added. So one can argue that because no prefix means default language in this mode, the system tries to generate you the shortest link possible. Admittedly, you already have a setting for this, you either specify the path prefix for the default language or not.

The idea behind this language mode was sites with a prominent default language, which is evident, so it does not have a prefix and then other languages, which need prefixing. This is doable without this code though by setting your default language prefix to empty for sure. That would lead to a more configurable system, albeit possibly harder to understand.

So committing this patch just removes a hardcoded assumption which is configurable otherwise.

meba’s picture

subscribe

gaele’s picture

Re #12: So the conclusion is "by design"?

I would like to keep the current situation. Otherwise adding a second language afterwards would break all existing incoming links.

Status: Needs review » Needs work

The last submitted patch failed testing.

lilou’s picture

Status: Needs work » Needs review
catch’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Quick fix

Since we already have a configuration option, which this essentially breaks, I think the patch is RTBC following Gabor's review.

webchick’s picture

Status: Reviewed & tested by the community » Needs review

Hmmm... Gábor, could you confirm that? It's late, but it seems like there is some contention in this issue about whether this is the best way to go or not?

Gábor Hojtsy’s picture

I can only repeat what I said in #12. Please read it carefully and let me know if something specific thing is not clear from there.

ogi’s picture

Then what about changing documentation. The following text contrasts the two problem options (any more appropriate suggestion for "proper language"?):

LANGUAGE_NEGOTIATION_PATH

  • Path based negotiation.
  • If no defined path prefix is identified, fallback to user preferences and browser language detection.
  • Insite URLs are rewritten to use proper language path prefix.

LANGUAGE_NEGOTIATION_PATH_DEFAULT

  • Path based negotiation.
  • If no defined path prefix is identified, fallback to default language.
  • Insite URLs are rewritten to use proper language path prefix only if proper language is not default language.

Status: Needs review » Needs work

The last submitted patch failed testing.

catch’s picture

Status: Needs work » Needs review
Issue tags: +i18n sprint

Status: Needs review » Needs work

The last submitted patch failed testing.

sokopok’s picture

I'd like to add some comments to this discussion. This issue has been bothering me for some time, but decided to just sit it out, wait for a fix. Now I started on a new site and got annoyed again...

The solution seems simple to me, but then again, I'm not a drupal expert, so I might be missing something, but just changing language_url_rewrite like this seems to work for me:

case LANGUAGE_NEGOTIATION_PATH_DEFAULT:
$default = language_default();
if ($options['language']->language == $default->language) {
if(!empty($default->prefix)) {
$options['prefix'] = $default->prefix .'/';
}
break;
}

This way, when no language prefix is present in the url the original behavior remains intact, but all internal links will be generated with a prefix. So you can distribute prefix-less url if you like and the presented language will be decided according to the default or user preferences upon the first page access.
For me it would be even nicer if the user would be redirected to the path-with-prefix, just to keep the url-space consistent, but that seems a minor issue.

There is one problem (as far as I can see) with this solution: When you change your preferred language in the user settings, this change is not directly apparent (since all links now have a prefix, you stay in the old language). But this could be fixed by redirecting after the user settings from has been submitted.

klance’s picture

This is a simple issue. First of all, for someone like me who runs a multilingual web site with thousands of URL aliases, retaining the language prefix for the default language is a simple matter of backward compatibility. My URL aliases weren't updated to reflect this change as part of the upgrade, so it feels like something conceived in haste. Secondly, having a "default" language goes against the whole i18n philosophy that all languages should be treated equally, which I believe Jose Reyero's i18n module achieved with great success. Finally, being able to add or remove the prefix in the language configuration, would have been the perfect compromise between the two schools of thought on this issue. That is, if it actually worked. But it doesn't. Whether or not you specify the prefix for the default language, it isn't added to URLs either way. Removing the prefix from languages other than the default has to screw things up, too, because where's your language reference? So is it a bug? My only out-of-the-box option is to add Zulu (or whatever) as my default language, making English and French alternative languages, so that the prefix is added to my menu links, which is every bit as absurd as it sounds.

Pasqualle’s picture

We need a new checkbox: "show language prefix in the url for the default language"
And we should really backport the patch to D6, as too many sites would like to use the language prefix in urls for the default language also.

Pasqualle’s picture

Ok after writing the patch I've just realized all I need is to switch from "Path prefix only" to "Path prefix with language fallback" and I will have the same result as with the patch.. But the info that "default language prefix will or will not be used in urls" is not written anywhere on this admin screen..
And this part:

If a suitable prefix is not identified, the display language is determined by the user's language preferences from the My Account page, or by the browser's language settings.

makes me to never choose this option..

This is really confusing..

erem’s picture

Hi Klance, Of course you run the risk of being confronted with a Zulu admin interface after an update ;) That said, this option seriously crossed my mind as well to get out of this multilingual tangle. So, did it work for you?

Danny_Joris’s picture

It's been more than a year since this issue is raised. I encounter the same problem. Is there a solution for D6, already?

Actually I also encountered another issue, that might be a bit related. And since I don't have any comments on it yet and this room is filled with quite some Drupal experts, I would like to share this with the crowd. http://drupal.org/node/568646
The spot where these two issues meet is: I'm building a website in French and Dutch. I cannot unable English properly (see link to issue). So that's why I can't use 'Path prefix with language fallback' because my front page will appear in English (or at least French or Dutch menus won't appear), because it will seek the user's browser language, which is English most of the time.

Any help is very welcome.
Cheers,
Danny

catch’s picture

Status: Needs work » Needs review
Issue tags: -Quick fix, -i18n sprint

#1: language_244162.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Quick fix, +i18n sprint

The last submitted patch, language_244162.patch, failed testing.

plach’s picture

Component: locale.module » language system

Cleaning-up the "locale module" issue queue as per http://cyrve.com/criticals.

klonos’s picture

Does this patch work against 6.x?

catch’s picture

Version: 7.x-dev » 6.x-dev
Status: Needs work » Reviewed & tested by the community

This is actually fixed in Drupal 7 since we have highly configurable negotiation settings now, and adding a prefix for default language makes it appear in URLs, at least if you do the equivalent of path prefix only.

#1 still applies without offset, still works great, and was RTBC over a year ago including a +1 from Gabor the D6 branch maintainer, so I'm setting that status back now.

klonos’s picture

That's good news for D7! Hope to see this fixed in D6 as well soon.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

@Pasqualle explained how you can configure your desired option even without this patch.

The patch makes LANGUAGE_NEGOTIATION_PATH_DEFAULT and LANGUAGE_NEGOTIATION_PATH work the same way. So why do we have two options then? If the author of the patch wanted the behavior of the second, why did he not configure his system that way?

I think best we could do is to improve the docs here as we've seen multiple people conflicted by what do the options really mean.

j0nathan’s picture

Hi,

Sorry I do not understand well the code and patches you are talking about, but what I would like in Drupal 6 is to have the language prefix in the path for all languages including the default language.

I do not want this setting from "My Account" page because I want to be able to switch from a language to another by clicking on the language switcher link, not by changing the configuration of my account. I do not want the language to be chosen from my browser for the same reasons.

I would also like to be redirected to the default language with its path prefix if there is no path prefix specified in the request. Maybe (not sure yet) only the frontpage in the default language could stay without any language prefix. It's important for SEO to not have duplicated pages with and without language prefix, so they have to be redirected.

I use i18n, Pathauto, Path Redirect, Global Redirect. Sometimes I use URL alter and Sub-path URL Aliases.

Is there actually a way to configure what I want ?
Or is part of this issue ?
I have not find any receipt for this, only this issue.

Thanks

EDIT:
I note that the module boost asks for "Path prefix only." and this is another reason to have to use this setting.

ikeigenwijs’s picture

I think i have the same issue.

when i add a node in french.
the pathprefix is still nl(my default language) instead fr.

I m searching for more than a week on this problem.

pleas advice

ikeigenwijs’s picture

I think the update 6.20 fixed this issue.
i lll be back in a few days to close this after some more testing.

nlambert’s picture

subscribe

Jerome F’s picture

Status: Needs work » Closed (works as designed)

I'm running 7.x dev and had some page not found errors.

I had to go to: admin/config/regional/language/configure
and check URL Determine the language from the URL (Path prefix or domain).

Reading through this issue, I think #12 means that it works like this by design.
Make sure your internationalization settings are correct.
Re-open if I'm misunderstood that.

Exploratus’s picture

This is still an issue. Need the default language to have a prefix....

knalstaaf’s picture

Version: 6.x-dev » 7.24
Issue summary: View changes
Status: Closed (works as designed) » Active

We need at least the choice to use the language prefix, even when there's only one language available.

Case: client uses multilingual site with language prefixes. Decides he only wants to use English. Prefixes disappear. Previous paths no longer available. SEO Destroyed.

Path prefix language code is set to "en" to no avail. The Global Redirect and Search 404 modules are not helping either.

When applying this htaccess-approach the urls get their prefix back, but return 404-pages.

This is concerning.

samsterlin’s picture

Priority: Normal » Major

We are using i18 module. Added 2 languages English and Tamil. English is a default language. while trying to switch the languages the laguage prefix (en or ta) is not added with the url automatically. Please send the way to fix this issue.

samsterlin’s picture

Status: Active » Fixed
David_Rothstein’s picture

Version: 7.24 » 7.x-dev
Status: Fixed » Closed (works as designed)

This was closed without comment, but I think #43 is a valid feature request. However it's only tangentially related to this issue, so I moved it to #2426885: Allow language prefixes/domains to be used even when only one language is available instead. Moving this one back to its earlier status. I'm not totally sure if there's an issue here still for Drupal 6 or not, but it sounds like from earlier comments there isn't.