0

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

0
3

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');
  }
}
2

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.
2
  • But what if there's existing content? Like 1000 nodes, all in en?
    – leymannx
    Oct 7 at 11:09
  • @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. Oct 7 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.