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.
Comment | File | Size | Author |
---|---|---|---|
#1 | language_244162.patch | 993 bytes | drewish |
Comments
Comment #1
drewish CreditAttribution: drewish commentedI tracked the problem down to
language_url_rewrite()
. The value of$options['language']
is either specified by the user or assigned theglobal $language
which is set bydrupal_init_language()
. If there is only a single language installeddrupal_init_language()
returns it, otherwise it callslanguage_initialize()
which property distinguishes between theLANGUAGE_NEGOTIATION_PATH_DEFAULT
andLANGUAGE_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.Comment #2
drewish CreditAttribution: drewish commentedI just discovered:
#237140: Default language ignores Path prefix
which I duplicated but since I've got a patch I'll leave this one active.
Comment #3
ogi CreditAttribution: ogi commentedsubscribe
Comment #4
Dries CreditAttribution: Dries commentedI'd like to see this patch reviewed by Gabor first. He is one of the main authors of the locale module.
Comment #5
link0ff CreditAttribution: link0ff commentedI 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.
Comment #6
drewish CreditAttribution: drewish commentedjurta, 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.
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.
Comment #7
link0ff CreditAttribution: link0ff commentedAs 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.
Comment #8
drewish CreditAttribution: drewish commentedjurta, there's an issue for that already: #146084: Default path prefix for English (and DBTNG it)
Comment #9
drewish CreditAttribution: drewish commentedoh, i just realized that you've already commented on that ;)
Comment #10
link0ff CreditAttribution: link0ff commenteddrewish, 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.
Comment #11
link0ff CreditAttribution: link0ff commentedIt 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?
Comment #12
Gábor HojtsyOk, let's read the help text for "Path prefix only" (which is the name for LANGUAGE_NEGOTIATION_PATH_DEFAULT):
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.
Comment #13
meba CreditAttribution: meba commentedsubscribe
Comment #14
gaele CreditAttribution: gaele commentedRe #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.
Comment #16
lilou CreditAttribution: lilou commentedSee: #335122: Test clean HEAD after every commit and http://pastebin.ca/1258476
Comment #17
catchSince we already have a configuration option, which this essentially breaks, I think the patch is RTBC following Gabor's review.
Comment #18
webchickHmmm... 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?
Comment #19
Gábor HojtsyI 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.
Comment #20
ogi CreditAttribution: ogi commentedThen what about changing documentation. The following text contrasts the two problem options (any more appropriate suggestion for "proper language"?):
LANGUAGE_NEGOTIATION_PATH
LANGUAGE_NEGOTIATION_PATH_DEFAULT
Comment #22
catchComment #24
sokopok CreditAttribution: sokopok commentedI'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.
Comment #25
klance CreditAttribution: klance commentedThis 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.
Comment #26
PasqualleWe 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.
Comment #27
PasqualleOk 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:
makes me to never choose this option..
This is really confusing..
Comment #28
erem CreditAttribution: erem commentedHi 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?
Comment #29
Danny_Joris CreditAttribution: Danny_Joris commentedIt'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
Comment #30
catch#1: language_244162.patch queued for re-testing.
Comment #32
plachCleaning-up the "locale module" issue queue as per http://cyrve.com/criticals.
Comment #33
klonosDoes this patch work against 6.x?
Comment #34
catchThis 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.
Comment #35
klonosThat's good news for D7! Hope to see this fixed in D6 as well soon.
Comment #36
Gábor Hojtsy@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.
Comment #37
j0nathan CreditAttribution: j0nathan commentedHi,
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.
Comment #38
ikeigenwijs CreditAttribution: ikeigenwijs commentedI 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
Comment #39
ikeigenwijs CreditAttribution: ikeigenwijs commentedI think the update 6.20 fixed this issue.
i lll be back in a few days to close this after some more testing.
Comment #40
nlambert CreditAttribution: nlambert commentedsubscribe
Comment #41
Jerome F CreditAttribution: Jerome F commentedI'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.
Comment #42
Exploratus CreditAttribution: Exploratus commentedThis is still an issue. Need the default language to have a prefix....
Comment #43
knalstaaf CreditAttribution: knalstaaf commentedWe 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.
Comment #44
samsterlin CreditAttribution: samsterlin commentedWe 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.
Comment #45
samsterlin CreditAttribution: samsterlin commentedComment #46
David_Rothstein CreditAttribution: David_Rothstein commentedThis 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.