Repository: gohugoio/hugo (language: go)

Issue:
tpl/tplimpl: Improve locale value in opengraph.html
https://github.com/gohugoio/hugo/blob/b1bf0bff2c8ce1e2cace5010a81911a3dbf8e674/tpl/tplimpl/embedded/templates/opengraph.html#L15-L17

Improvements:

1. With v0.112.0 and later, `site.Language.LanguageCode` falls back to `site.Language.Lang`, so the explicit fallback above is not required.
2. Contrary to RFC 5646, the opengraph protocol requires an underscore instead of a hyphen in the locale.

Proposed change:

```text
{{- with or .Params.locale site.Language.LanguageCode }}
  <meta property="og:locale" content="{{ replace . `-` `_` }}">
{{- end }}
```


Discussion / hints:

Fix patch:
diff --git a/tpl/tplimpl/embedded/templates/opengraph.html b/tpl/tplimpl/embedded/templates/opengraph.html
index a9b348e9ef0..59e63d6be56 100644
--- a/tpl/tplimpl/embedded/templates/opengraph.html
+++ b/tpl/tplimpl/embedded/templates/opengraph.html
@@ -12,8 +12,8 @@
   <meta property="og:description" content="{{ . }}">
 {{- end }}
 
-{{- with or .Params.locale site.Language.LanguageCode site.Language.Lang }}
-  <meta property="og:locale" content="{{ . }}">
+{{- with or .Params.locale site.Language.LanguageCode }}
+  <meta property="og:locale" content="{{ replace . `-` `_` }}">
 {{- end }}
 
 {{- if .IsPage }}


Test patch:
diff --git a/tpl/tplimpl/tplimpl_integration_test.go b/tpl/tplimpl/tplimpl_integration_test.go
index 6b2664c4d84..f9d25eb49f3 100644
--- a/tpl/tplimpl/tplimpl_integration_test.go
+++ b/tpl/tplimpl/tplimpl_integration_test.go
@@ -372,7 +372,7 @@ series: [series-1]
 		<meta property="og:url" content="/s1/p1/">
 		<meta property="og:title" content="p1">
 		<meta property="og:description" content="a b and c can’t.">
-		<meta property="og:locale" content="en-US">
+		<meta property="og:locale" content="en_US">
 		<meta property="og:type" content="article">
 		<meta property="article:section" content="s1">
 		<meta property="article:published_time" content="2024-04-24T08:00:00-07:00">