I cannot programmatically create a node in anything other than en
language.
My site has 3 languages:
- en
- fr
- de
And the code for creating a node is:
define('DRUPAL_ROOT', ...);
require_once DRUPAL_ROOT . 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$node = new stdClass();
$node->type = "foobar";
node_object_prepare($node);
$node->title = 'test title';
$node->uid = 1;
$node->language = 'fr'; // *** this doesn't seem to work
if ($node = node_submit($node)) {
node_save($node);
}
No matter what I type in the $node->language = '...';
the result is always the same. The node is created in the English language. I confirm that via looking at admin/content
.
I've even tried stuffing this variable with a proper language object which I got out of the enabled languages of my site:
$languages = language_list('enabled');
$lang = $languages[1]['de'];
$node->language = $lang;
node_submit()
always returns the parameter passed to the function; there is no need to check the value returned from the function. – kiamlaluno♦ Jul 25 '12 at 13:39