default node language

Pasqualle - September 20, 2008 - 17:24
Project:Drupal
Version:7.x-dev
Component:locale.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:duplicate
Issue tags:i18n sprint
Description

when a multilingual support is disabled for given node type, then a saved node should not have language set in {node} nor in {url_alias} table, it should be saved with language = NULL

the problem is that some links will not show the url alias but shows the internal link, because the url alias does not exists for the actual language.. so I have to change the language manually for these nodes..

#1

Pasqualle - September 20, 2008 - 18:09

the problem is in locale_form_alter() function with this code snippet

        // Node type without language selector: assign the default for new nodes
        elseif (!isset($form['#node']->nid)) {
          $default = language_default();
          $form['language'] = array(
            '#type' => 'value',
            '#value' => $default->language
          );
        }

#2

Pasqualle - February 20, 2009 - 23:51
Version:6.x-dev» 7.x-dev
Status:active» needs review

also changed the default language for multilingual nodes, because that should not default to Language neutral.

AttachmentSizeStatusTest resultOperations
311158_node_language.patch1.48 KBIdleUnable to apply patch 311158_node_language.patchView details | Re-test

#3

brucepearson - February 23, 2009 - 02:20
Status:needs review» needs work

The patch doesn't work for me, it still sets the language selector to "Language neutral".
When the locale_form_alter is called $form['#node']->language is set to an empty string.

Maybe change:

'#default_value' => (isset($form['#node']->language) ? $form['#node']->language : $default->language),

to

'#default_value' => (isset($form['#node']->language) && $form['#node']->language != '' ? $form['#node']->language : $default->language),

#4

Pasqualle - February 23, 2009 - 03:31

When the locale_form_alter is called $form['#node']->language is set to an empty string.

I see, that is a problem.

But I think your modification changes the node language even when you edit it, not only at node creation. Can you confirm that when you open a node for edit which is "Language neutral", it changes to default language automatically? That should be wrong also..

#5

brucepearson - February 23, 2009 - 04:15

you are right - my modification wont work when you edit a node that is "Language neutral".

Maybe it would be better to just see if we are editing a node then and set the default language only if it is a new node.

We can check for the nid:

'#default_value' => (isset($form['#node']->nid) ? $form['#node']->language : $default->language),

#6

Pasqualle - February 23, 2009 - 04:29

that smells like a little hack to me :) The code should be easily readable. You are mixing two things here, at least it should be changed to an if statement with an explanation written in the code comment.

note: the isset($form['#node']->language) is used to avoid php notices, and possible problems. (although I do not know now, how could that isset() return false)

#7

Pasqualle - February 23, 2009 - 04:33

but the good solution would be to not set the node language outside the locale module. I do not understand why it is set to an empty string.

#8

Pasqualle - February 23, 2009 - 04:36
Title:language is set for non multilingual node» default node language
Component:path.module» locale.module

#9

brucepearson - February 23, 2009 - 05:06

It looks like it is being set in the node module, node.pages.inc, function node_add

    $node = array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => '');

#10

plach - March 1, 2009 - 11:24

subscribe

#11

Pasqualle - March 1, 2009 - 18:26

the node.module uses the node language property, and it would be hard to remove. So I am fine with the isset($form['#node']->nid) check, just the code needs to be more readable..

#12

Pasqualle - May 17, 2009 - 22:02

#13

mrbuom - May 21, 2009 - 08:07

#14

mrbuom - May 21, 2009 - 08:08
AttachmentSizeStatusTest resultOperations
locale.module.patch870 bytesIgnoredNoneNone

#15

cronix - June 19, 2009 - 19:14

I am looking for something similar. I have made a vocabulary with language specific terms. This vocabulary is used in my forum. That way I have have a multi lingual forum because the forum page will only show the terms in the current site language. That is working perfectly. My issue is that the forum posts are posted language neutral and not in the current site language. Has anyone found a solution for that? I am using D6.12

#16

smartmark - July 1, 2009 - 09:19

Mrbuom's patch (#14) works perfectly, thanks!

#17

alienzed - August 12, 2009 - 21:57

#14: awesome, thanx

#18

boran - October 27, 2009 - 13:45

#14 worked fine for me on D6.14 too.
A pity core has to be hacked and this fixed has not been included in core over the last few months..

There is also a thread on removing "Language neutral", that was also needed for my multi-language form site, perhaps it interests other readers: http://drupal.org/node/250891

 
 

Drupal is a registered trademark of Dries Buytaert.