Hello,
I'm not sure whether this is an issue with the i18n module or the core translation module...
- I've installed the Locale, Content Translation and Internationalization modules on a clean Drupal 6.3
- set up 2 languages domain-based language negotiation (e.g. http://drupal for primary language and http://de.drupal for second language)
- and then created a new page in the primary language (node/1, english) plus a translation in my second language (node/2, german)...
Now, when I go to the translation table (translation tab on nodes) I get a table listing the current node and it's translation as expected.
In that table the node titles link to their respective node views and the edit links to respective node edit forms. My problem is: Both links don't seem to be localized.
That is: If I'm currently on http://drupal then the link for node 1 looks like http://drupal/node/1 which is fine, but the link for node 2 (which is a german page) looks like http://drupal/node/2 where I think it should be http://de.drupal/node/2 (using the path of the node's language).
This probably doesn't pose a problem for most people because drupal doesn't care if a node's translation doesn't match the current page language... but if you try to change that behaviour by doing something like described in this issue those links stop working.
So I guess what I'm asking is whether I can somehow change those links in the translation table to make them localized ones?
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | translation-284625-45.patch | 6.59 KB | plach |
| #43 | translation-284625-43.patch | 6.56 KB | plach |
| #38 | translation-284625-38.patch | 6.35 KB | plach |
| #36 | translation-284625-36.patch | 5.75 KB | plach |
| #27 | 284625-27-translation-table-links.patch | 4.57 KB | bforchhammer |
Comments
Comment #1
bforchhammer commenteduh, wrong project.
Comment #2
bforchhammer commentedI think I found a solution myself...
Adding the current link's
$languageto the$optionsarray of the link function solves the problem... Attached is a patch for Drupal 6.3 doing exactly that.Are there any downsides to this solution that I'm not aware of?
Comment #3
bforchhammer commented10 weeks later and I still think this would make sense and should be implemented...
Comment #4
bforchhammer commentedComment #5
bforchhammer commentedComment #6
R.Muilwijk commentedReroll against head.
Comment #8
R.Muilwijk commentedHmmz.. fixed the typo's.
Comment #9
plachl()needs a language object, not a language code.Moreover we need a test ensuring we won't break this behavior in the future.
Powered by Dreditor.
Comment #10
R.Muilwijk commentedHmmz plach normally I would agree but look at current core code, line number 50:
http://drupalcode.org/viewvc/drupal/drupal/modules/translation/translati...
At the moment in the same function it already uses $language->language which I followed. Should all 3 instances be fixed to give the language object?
Comment #11
plachAt line 50 the language code is used to format the query string not as an option for
l(). See http://api.drupal.org/api/function/url/7 for details.Anyway I tested the patch and it does not work without the fix I suggested.
Comment #12
R.Muilwijk commentedOh, that is true. I'l reroll!
Comment #13
bforchhammer commentedHere's a re-roll against current head using language objects, and added for the third link ("create translation") as well. Tests are still missing (need to read up on that topic first).
Note that this doesn't work at all when using the administrative overlay, probably related to #759844: Overlay does not work with prefixed URL paths.
Comment #14
plachComment #16
bforchhammer commented#13: 284625-#13.patch queued for re-testing.
Comment #17
plachIt seems the patch is somehow corrupted. Can you post it again?
Comment #18
bforchhammer commentedHm, here we go...
Comment #20
plachYou need to reroll the patch from the drupal root.
Comment #21
plachHowever this does not work when adding a translation in a disabled language (see #356036: Allow creating nodes in disabled languages). You should use http://api.drupal.org/api/function/language_negotiation_get_switch_links/7 for each path to get the proper URL for each language.
Comment #22
bforchhammer commentedHere's the patch again, hopefully working now.
About #21: I can't imagine a case where it would make sense to "link to a language path" when the language is disabled. So isn't that something that should perhaps be handled inside the url() function?
Comment #23
plachIt's pretty easy to reproduce: enable french and german, disable french and then try to add a translation for it (if you can't see a use case for this please read the issue above). As language negotiation works only with enabled languages /fr/node/x won't work. However I performed some tests and this turned to be another issue.
Edit: related issue: #926212: URLs rewritten with disabled languages.
Comment #24
plach@bforchhammer:
The patch looks good and works as intended. If you provide a simpletest I'm ready to RTBC it.
Comment #25
bforchhammer commentedAttached is my attempt at providing tests.
This is my first time using the testing framework; feel free to point me to guidelines or documentation which I might not have followed...
Comment #26
plachOther than the minor coding standard issues below this looks good to go :)
The whitespace between the method parenthesis and the arumgent shouldn't be there.
idem
Powered by Dreditor.
Comment #27
bforchhammer commentedCool :) Attached patch fixes the whitespace issue.
Comment #28
plachNice!
Comment #29
plach@bforchhammer:
Sorry for changing status but #926212: URLs rewritten with disabled languages should be fixed before committing this, otherwise we would introduce a major core misbehavior.
Could you stay tuned over there? I'll try to provide a simple test ASAP. If you can test and review it too, this would speed up the commit of this issue. I'll RTBC this again once the other one is RTBC.
Comment #30
plach@Dries, @webchick:
Before committing this, be sure to commit #926212: URLs rewritten with disabled languages as this exposes the bug fixed over there.
Comment #31
plachAfter some additional testing I realized that the last patch is incomplete: if you enable the Session language detection method instead of the URL one the translation links are still unlocalized.
As I suggested in #21 we should use http://api.drupal.org/api/function/language_negotiation_get_switch_links/7 to obtain the proper localized links. We must also keep in mind that when no language detection method is enabled its result will be empty, but in this case we don't need localized links.
Comment #32
bforchhammer commentedNot sure how the session language detection works... is there a way to change the session language with the click of a link? If not this is going to be hard to solve (?).
I shouldn't be that hard to tell a link to be rendered localized in a different language; from my naive developer perspective I would say that the current implementation is the most logical one and if this isn't working for certain types of language negotation then maybe that's a defect in the url() function (or related ones).
Comment #33
plachThis is not a defect in
url(): in the latest patch we are esplicitly providing an option to change the language, but this concerns only URL language, while to switch session language we need to provide a query parameter. But this would not take into account any other possible contrib language detection method. http://api.drupal.org/api/function/language_negotiation_get_switch_links/7 does by invoking all the defined language switch callback functions. Using it is not that hard after all.Comment #34
bforchhammer commentedI think I understand the difference between what the two functions
url()andlanguage_negotiation_get_switch_links()do (thanks to catch@irc), but I don't quite get why there is a difference -- I can't imagine a case where one would pass the language object into the url() function and then NOT want to actually switch languages when clicking the resulting link.Of course I don't want to unnecessarily hold this issue back, so if the
language_negotiation_get_switch_link()function is the way it has to be I'll adjust my patch...Comment #35
plachI understand you perplexity: the reason is that with the new language negotiation API a URL can convey an arbitrary number of language types, so we can't simply rely on
$options['language'].Comment #36
plachLet's try this.
Comment #38
plachTests should pass now.
Comment #39
bforchhammer commentedThat's working nicely. :-)
Comment #40
tom_o_t commented#38: translation-284625-38.patch queued for re-testing.
Comment #41
webchick#38: translation-284625-38.patch queued for re-testing.
Comment #42
webchick#926212: URLs rewritten with disabled languages committed. Sent for a re-test.
However, I reeeeeeeeally am not a fan of introducing a "special" l() function here. Can we just include that code in translation_node_overview()?
Comment #43
plachAnd here it is :)
Comment #45
plachthis should work
Comment #46
webchickThanks!
Committed to HEAD.