When viewing a node, the country switcher should link to the appropriate node for each country - currently it changes the country code in the path, but this doesn't affect the node being displayed.
Translation module does this with translation_translation_link_alter(), translation_path_get_translations() for the language switcher block - looks like we need to implement something similar in country_code().
This was reported by Roger Lopez in irc.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | countrylinks.patch | 1.77 KB | catch |
Comments
Comment #1
zroger commentedSo i looked at how locale does this for the language switcher.
Translation.module implements hook_alter_translation_link to change href's to the correct translation. The hook is invoked from the locale language switcher block.
Since the country switcher block already invokes a similar hook, hook_alter_country_code_link, i added a hook implementation to do the same thing for country switcher links.
I've written this hook implementation on behalf of translation module, but I'm still not sure that is the _right_ way to do it. Changing the name to country_code_country_code_link_alter works just as well.
Patch works well for me.
Comment #2
catchI've committed the following patch, which seems to be working.
Its untested with more than one translation per country, so may well need tweaking for that, and needs some more testing in general.
Comment #3
catchCommitted an additional fix to include the country path. All quite quick work, could do with proper review and testing.
Since I'm foreaching through all nodes in a tnid, if there's more than one language per country, and a translation in more than one of those languages for the node that's being viewed, then it currently just overwrites the link with the last loaded node. We need to either eliminate duplicates in the query (I'm just using a function from translation.module to get translations sets by tnid at the moment), or do some filtering in the array itself.
I'm also not 100% sure what should happen when the node isn't attached to a country (i.e. a global node) - at the moment, the links are left as is in that case.
I also noticed that the result of country_code_language() differs when you click links in the country switcher, but not necessarily when you click links in the language switcher - that makes some of the more edge case behaviour hard to test. Will open a new issue for that.
Comment #4
nedjo@Roger López and catch: good work tracking down this issue. The existing patch does some of what we need but needs some revising.
I don't think we need to alter our own link. Rather, we can do this straight in the hook_block() implementation.
It's an interesting problem. To get it right, I'm thinking, we have to anticipate what language will be set if the user switches to a given country. What we want to link to I think is:
1. A country-specific version of the node in the to-be-set language, if one exists. E.g. fr-CA if the link is for Canada and the language will be French.
2. A generic (global) version of the node in the to-be-set language, if one exists. E.g. 'fr'.
3. If neither exists, a different page, likely the home page, since there isn't a version of this node in the language that will be set.
The hard part is ensuring we correctly determine what language will be set, since our logic for that is complex. We need to ensure that decision is isolated in a function that will accept a country passed in. Then we can load the paths of the translation set, test for the languages, and we're good.
I'll have a crack at this.
Comment #5
stella commentedI've tested this and the module is now successfully switching content, but as already noted the language handling needs to be improved upon. Let me know when there's a new version and I'll test some more.
Cheers,
Stella