Problem: in Drupal 7 if you enable language support, add a couple of languages and add content in them, you cannot actually enable a language switcher or use language dependent URLs until you go and configure it manually. You can enable the language switcher block but it will not show up. The language selection (negotiation) settings are empty at the start, so the default language is used at all times.
Proposal: default the language negotiation settings to URL path prefix, so that the most commonly used (and out-of-the-box workable) solution is the default, which makes working with languages easy right away. Only those who are not fine with this setting will need to go and configure language settings. We'd lead ith sensible defaults for the 80%.
Comment | File | Size | Author |
---|---|---|---|
#34 | locale-1280538-34.patch | 6.88 KB | Gábor Hojtsy |
#31 | locale-1280538-31.patch | 2.97 KB | Gábor Hojtsy |
#25 | locale-1280538-25.patch | 1.41 KB | plach |
#22 | locale-1280538-3.patch | 2.21 KB | fastangel |
#19 | locale-1280538-2.patch | 971 bytes | fastangel |
Comments
Comment #1
Bojhan CreditAttribution: Bojhan commentedWait, does this mean on install someone needs to specify multilingual or not?
Comment #2
Gábor HojtsyWell, it would mean that either (a) we add the default foreign language without a path prefix or (b) your new foreign single language site will have a path prefix until you kill this setting. I think (a) is more likely :)
Comment #3
Gábor HojtsyComment #4
Gábor HojtsyFix project/component.
Comment #5
Gábor HojtsyYes, we should add the default foreign language without a prefix when installed in a foreign language. Then having the path prefix based negotiation has no effect until you add another language, when there needs to be some differentiator, which is going to be the path. Then without extra configuration, the added language would work right away (ie. language switcher block, etc). This removes an extra step and a sizable area to understand from language configuration, making language setup way easier, so it is going to be a huge plus IMHO. To reiterate, the tasks are:
1. When Drupal is installed make sure there is only one language added. If its the default English, make sure it has no prefix set. When it is some foreign language, make sure it has no prefix either. If it is a foreign language, we should not have English there at all.
2. Configure language negotiation with the URL based method and path prefixes.
Comment #6
Gábor HojtsyThis is probably much easier to implement once #1301460: Decouple domain/path language negotiation storage from language config storage lands (which is hopefully soon).
Comment #7
Gábor HojtsyThat landed, so now this should be pretty simple to do. :) Any takers?
Comment #8
fastangel CreditAttribution: fastangel commentedI work in this issue.
Regards.
Comment #9
fastangel CreditAttribution: fastangel commentedHi,
I am working how implements this feature. I have a small question. In the default profile the module locale is not active. Then the prefix and negotation isn't active. Does it make sense then put prefix in the install?
Regards.
Comment #10
Gábor Hojtsy@fastangel: well, this issue is about the installation of locale.module that handles the negotiation configuration. So when locale_install() is called, it would set up a default negotiation config that is not empty. In Drupal 7 the default config is empty, so you can keep adding languages but never be able to switch to them, since there is no URL or other setup that can be used to access them. If we default to URL path prefix negotiation when locale module is installed (and the initial language is saved with an empty prefix), the initial behavior is still identical to how Drupal 7 worked, that is the default language is used and no changes are made to the URLs, but when you add a second, third, etc. language, those would work right away since they get their prefixes.
So the idea here is to have smarter defaults for the user and make the system work better out of the box without compromising the initial simplicity of the system and the URLs backward compatibility when locale is installed.
Did this explanation help?
Comment #11
fastangel CreditAttribution: fastangel commentedOk. I think you understand better. When active module locale in function install I must turn negotiation with url (Option URL in admin/config/regional/language/configure). Taking intoaccount the restrictions discussed (
).
In short, the restrictions is that prefix is empty in all languages.
Is the right thing to say?
Regards
Comment #12
Gábor HojtsyWhen locale is installed, it already ensures the prefixes are set up as discussed, see locale_install().
Comment #13
fastangel CreditAttribution: fastangel commentedAttach patch. I put the code in locale_enabled because locale_install already not exists (In one of your most recent patches are removed).
Regards.
Comment #15
Gábor Hojtsy@fastangel: do you expect a module to change settings when you disable and then enable it?
Comment #16
Gábor HojtsyI'll answer my own question then. No, you don't want to have your settings change when you disable and then enable a module. The code in locale_enable() merely updated locale module's settings to the new realities of a language list that might have changes inbetween locale module not being enabled and language module being enabled.
So let's do this in a locale_install() instead. Then we should look at which tests fail and update the tests for the new assumptions for language negotiation preconfiguration IMHO.
Comment #17
fastangel CreditAttribution: fastangel commentedSorry for my late response :( . I am working on it.
Regards.
Comment #18
Gábor Hojtsy@fastangel: any updates?
Comment #19
fastangel CreditAttribution: fastangel commented@Gábor: Attached new patch with implement in locale_install. If there is any test to pass I start to work on it. Sorry about the time but I have been a few days away. Already back with renewed vigor. :D
Comment #21
fastangel CreditAttribution: fastangel commentedI work in the pass the test.
Comment #22
fastangel CreditAttribution: fastangel commentedHi,
I attached a new patch. I have a one question. For test Translation functionality I don't know how to fix it.
Regards.
Comment #24
Gábor Hojtsy@fastangel: url() should never get the language code prefix like in your change. I'll ask @plach to help you out since that seems like the most time effective :) He is the architect behind the language negotiation system :)
Comment #25
plachThis should be ok, tests yet to be fixed.
We should not need to care about prefixes since they are ignored on monolingual sites and multilingual ones with all prefixed languages work just fine.
Comment #27
Gábor Hojtsy@plach: I don't really understand this code comment:
Emphasis mine. Also, I assume the test fails are due to how the tests assumed a pristine negotiation environment, and they should not assume that anymore, right?
Comment #28
plachWell, language_negotiation_set() relies on hook_language_negotiation_info() definitions: the URL detection method is defined in locale.module which is not enabled yet, hence we must replicate its logic manually.
Didn't look at those yet, just tested the patch manually and it seemed to work well. I guess some tests currently don't expect a prefixed URL.
Comment #29
Gábor HojtsySo the comment would be more like this?
Comment #30
plachYes :)
Comment #31
Gábor HojtsyHere is a slightly updated patch. It fixes the comment that I noted and also a test in locale.test. I was debugging the UI language test when I figured out that the approach taken might not be good. Your code seems to set up all language types to have URL negotiation only, right? That kills the fallback negotiation setup that is default for "hidden" types, no? That is what I'm seeing with the testUrlLanguageFallback() test in locale.test I assume. Is that not the case?
Comment #32
plachNo, it should update only configurable language types, i.e. currently only UI language. When entity translation lands we might want to switch on content language too, and that code would be future-proof.
Comment #34
Gábor HojtsyOk, then we need to pass a language in $options for url() that would generate a language independent URL, so that we can get a URL that is useful for detection testing without an URL component to it. Added that fix in the patch.
Also looked into the path test failure and tracked it down to http://api.drupal.org/api/drupal/core--modules--locale--locale.module/fu... calls locale_language_url_rewrite_url() properly but then that function has a static cache of languages that was not cleared, so it was not yet aware of French being present and available. Fixed that too.
Finally, in the translation module tests, Italian is originally used as a disabled language to use for assigning to content. Then it is enabled so it shows up in the language switcher blocks. But the simpletest-side caches are not cleared there either, so the path being looked for is not properly constructed, which made the tests fail for the previously disabled language. If we clear the static caches proper after enabling Italian, then these pass too.
(While debugging I also found a $language in url() that is in fact a language code. It in fact uses $language first for an object then re-assigns to a langcode. That should have been a $langcode, so modified that too.)
Attached patch should now pass all tests. Reviews please!
Comment #35
Gábor HojtsyComment #36
plachLooks good!
Comment #37
Dries CreditAttribution: Dries commentedCommitted to 8.x. Thanks.
Comment #38
Dries CreditAttribution: Dries commentedComment #39
Gábor HojtsyAdded a changelog entry at http://drupal.org/node/1413776 to document this for site builders and test authors.
Comment #40
Gábor HojtsyTagging for base language system.
Comment #41
Gábor HojtsyTagging for language negotiation too.
Comment #42.0
(not verified) CreditAttribution: commentedConcise summary of the goals.