Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Drupal 7
Here is my code:
$languages = language_list(); // get all languages
$preferedLang = "sv";
global $language;
$language = $languages[$preferedLang];
$node = new stdClass(); // Create a new node object
$node->type = $type; // Or page, or whatever content type you like
node_object_prepare($node); // Set some default values
$node->title = $title;
$node->language = $preferedLang; // Or e.g. 'en' if locale is enabled
$node->path['pathauto'] = TRUE;
.
.
.
node_save($node);
When the title is set to
Jakt på vildsvin och dovhjort erbjuds i norra Östergötland
it should use Transliteration and produce this path:
/jakt-pa-vildsvin-och-dovhjort-erbjuds-i-norra-ostergotland
Instead the following (incorrent, not transliterated path) is created
/jakt-p-vildsvin-och-dovhjort-erbjuds-i-norra-stergotland
Note that "å" did not transliterate into "a" and "Ö" into "o".
Also note that if I create the node manually this works.
What I have done:
- Verified that I have checked "Transliterate prior to creating alias"
- Verified that I have both English and Swedish languages enabled
Finally, I have tried setting:
$path["language"] = 'sv'
as well as made the $language variable global