Score:1

Change langcode

br flag

How can I change the entire site <html lang="en"> to <html lang="en-US">? I couldn't find anything on the Internet.

Andrew Magill avatar
uy flag
Question is too vague.
Score:3
gb flag

If you want to do it programmatically you can use hook_preprocess_HOOK like the this:

/**
 * Implements hook_preprocess_HOOK().
 */
function [MODULE|THEME]_preprocess_html(&$variables) {
  /** @var \Drupal\Core\Template\Attribute $html_attribute */
  $html_attribute = $variables['html_attributes'];
  if ($html_attribute->hasAttribute("lang")) {
    $html_attribute->removeAttribute('lang');
    $html_attribute->setAttribute('lang', 'en-US');
  }
}
Score:2
cn flag

You can do this by adding en-US as a custom language.

  1. Go to /admin/config/regional/language.
  2. Click Add language.
  3. Choose Custom language... from the bottom of the list.
  4. Enter the language code and language name.
leymannx avatar
ne flag
But what if there's existing content? Like 1000 nodes, all in `en`?
cn flag
@leymannx If the site is monolingual, you can just delete the original `en` English. If there are multiple languages, you can probably use VBO to convert them.
Score:0
in flag

Drupal 8 and laters can handle this via UI.

This is how I set proper lang code in a multilanguage content website.

  • add/set up languages [/admin/config/regional/language]
  • set up language detection (optional) [/admin/config/regional/language/detection]
  • set up language behaviours for a multilanguge content type you want translated in more languages [/admin/config/regional/content-language]
  • translate your node in more languages.

You can now switch node traslation and compare lang codes

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.