I am not sure this is isolated to 4.7.0-beta3. I have not enabled more than one language for DRUPAL in a while.
I have two languages on my site: Chinese and the build-in English. My normal setting is that Chinese is default and English is even not enabled. For testing purpose, I tried to enable English after updating my test site to 4.7 beta3. After hit "submit", the check box for English is un-checked again. There is no error message in drupal system log. Go to an user account page, there is no option to pick a language.
I can however switch the default language to English. However after "submit", Chinese will no longer be enabled. So it seems in my installation, one can pick which language as the default language but can't enable another language as an option for users.
Comment | File | Size | Author |
---|---|---|---|
#13 | locale_system_1.patch | 2.26 KB | killes@www.drop.org |
#8 | locale_system_0.patch | 2.18 KB | riccardoR |
#6 | locale.module_1.patch | 1.21 KB | riccardoR |
#3 | locale.module.patch | 1.25 KB | riccardoR |
Comments
Comment #1
riccardoR CreditAttribution: riccardoR commentedI have the same problem with 4.7.0-beta3 when trying to enable two languages (English and Italian).
Here is my little workaround for this problem.
As it is my first patch to Drupal, I am not sure if it is the best one, but at least it works on my system.
IMHO the problem is that the checkbox for enabling/disabling a language returns the language key (when checked) or null,
while the enabled field in the DB is an int flag (i.e. 0/1).
So I convert the flag in locale.module before storing it into DB:
--- locale.module 2006-01-09 20:22:04.000000000 +0100
+++ locale.module.new 2006-01-11 15:45:27.666902400 +0100
@@ -274,6 +274,7 @@
// Save changes to existing languages
$languages = locale_supported_languages(FALSE, TRUE);
foreach($languages['name'] as $key => $value) {
+ $edit['enabled'][$key] = $edit['enabled'][$key] ? 1 :0; // !!! This line has been added
if ($edit['sitedefault'] == $key) {
$edit['enabled'][$key] = 1; // autoenable the default language
}
Hope this helps
Comment #2
riccardoR CreditAttribution: riccardoR commentedI'm sorry.
It was my first post here and I unintentionally changed the title.
Comment #3
riccardoR CreditAttribution: riccardoR commentedI have done further testings and I am quite sure that Xiang is right:
on 4.7.0-beta3 you can enable only the default language, because the others are always disabled.
Note that it's not a display problem: they are actually disabled into the DB.
I think it is good to raise the priority of this issue to normal, as I understood from Dries' blog that localization is an important functionality :)
I have reviewed my previous workaround, so this patch is different from what you see on #1.
About the issue :
The values returned by the checkboxes to enable/disable a locale are as follows :
- the locale when checked (e.g. 'en' for English)
- an empty string when unchecked
(The same happens with the checkboxes to enable/disable themes, so it is correct).
The locale_admin form is processed by locale_admin_manage().
The issue seems to be caused by the call to db_query, which stores the locale enabled flags into locales_meta.enabled that is an integer.
The implicit type cast to integer of a string like 'en', 'it', or an empty string always result in 0.
IMHO the cleanest thing to do here might be to explicitly cast the string to boolean on the call to db_query(), so that it can be safely converted to an integer by db_query() itself.
I tested the patch and it works, but it is my first patch. Therefore a good review is surely required.
RiccardoR
Comment #4
Dries CreditAttribution: Dries commentedIsn't an isset() cleaner than casting a string to a boolean? Would that work, or not quite?
What exactly is the value of $edit['enabled'][$key]?
Comment #5
Xiang-2 CreditAttribution: Xiang-2 commentedApplied the attched patch in #3 submitted by riccardoR (thanks!) It worked on my site to the extend that the form is now processed correctly. However, with both English and Chinese enabled, registered users still don't have an option to select which language to use on their account editing page. I have not found if there is something else admin need to do to have this language option show up in account edit page (did do a quick check in "access control").
Comment #6
riccardoR CreditAttribution: riccardoR commentedThanks Dries.
Indeed isset() is cleaner and works great : change attached.
The value of $edit['enabled'][$key] is the locale id ('en', 'it', etc.)
or an empty string.
Comment #7
riccardoR CreditAttribution: riccardoR commentedConcerning the second issue reported by Xiang (the language selector is not present on user account editing page),
I think it is because $form['locale'] defined on locale_user() :
is overwritten on system_user() with the user timezone selector:
I also noticed that the user timezone selector is not enclosed by a border (frameset), like it was on 4.6.5.
I think both the issues can be fixed with a slight change to system_user() :
The user language selector is now displayed and the timezone selector has a border. I tested it, but...
Please, an experienced reviewer is really appreciated. Thanks.
Comment #8
riccardoR CreditAttribution: riccardoR commentedThis patch fixes the two issues on localization reported by Xiang :
- It is not possible to enable more than one interface language on "administer localization".
( locale_admin_manage() : the value of $edit['enabled'][$key] can be null or a locale id (like 'en', 'it', ecc.),
but it is written into the database as an integer, which value is always 0 ).
- Users cannot select their preferred interface language on "edit user account";
( $form['locale'] returned by system_user() overwrites $form['locale'] returned by locale_user().
The two functions are invoked as hooks by _user_forms() and their return values are merged by calling
array_merge() ).
This patch, moreover, fixes a cosmetic issue, which I discovered while testing "edit user account" :
- The timezone selector is not framed by a fieldset, as it was on 4.6.5.
Concerning cosmetic, in my opinion "edit user account" would be cleaner if "Interface language" and "Timezone" were displayed in the same frame :
Locale settings :
-- Interface language
-- Timezone
I tried to do that, but it seems very complicated, because the hook_user functions of two different modules (locale and system) are involved. Does someone have any opinion or suggestion on this subject?
Please load the patch and review it. Many thanks.
Comment #9
Xiang-2 CreditAttribution: Xiang-2 commentedApplied patch submitted by RiccardoR on January 15, 2006 (locale_system_0.patch (2.18 KB)). Both bugs reported here fixed. No new issue noticed. Thanks!
Comment #10
Cvbge CreditAttribution: Cvbge commentedIf you say that the value can be NULL/string, then the isset() will work. But previously you said it is ''/string, which would not work. But since you tested and it works, it's NULL/string, right?
Comment #11
riccardoR CreditAttribution: riccardoR commentedThanks Cvbge!
It's actually NULL/string.
I will be more careful with terminology next time.
Comment #12
Dries CreditAttribution: Dries commentedThe patch appears to be malformed?
Comment #13
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedRe-rolled patch
Comment #14
riccardoR CreditAttribution: riccardoR commentedDries, Killes,
I guess this is the right move now.
as I said it is my first patch...
Am I missing something?
Thank you.
Comment #15
mgiffordJust to confirm that this patch worked for me on the cvs version:
locale_system_1.patch (2.26 KB)
Comment #16
toemaz CreditAttribution: toemaz commentedI confirm it too!
Comment #17
Dries CreditAttribution: Dries commentedCommitted to HEAD. Thanks.
Comment #18
(not verified) CreditAttribution: commented