Configuring `og:locale` for multilingual site

I generated my own open graph tags. Does Hugo have the option in language configuration for generating language_territory codes? I couldn’t find it in the language docs. (And I just found out one year later that my og:locale has been wrong for the translated site.)

1 Like

That belongs in site configuration. See https://gohugo.io/content-management/multilingual/.

[languages.de]
  contentDir = 'content/de'
  disabled = false
  languageCode = 'de-DE'          <-- this is for locale
  languageDirection = 'ltr'
  languageName = 'Deutsch'
  title = 'Projekt Dokumentation'
  weight = 1

In templates do this:

{{ or .Site.Language.LanguageCode .Site.Language.Lang }}

The languageCode value is (currently) only used in templates; it is not used internally for translations or localizations.

Depending on who/what is consuming the languageCode, you may have to convert between hyphens and underscores. For example:

{{ or .Site.Language.LanguageCode .Site.Language.Lang | replaceRE `-` "_" }}

Although RFC 5646 explicitly requires hyphens, I guess some consumers (e.g., Facebook) want underscores. Yuck.

My question was related to this actually since OGP also requires underscores. I guess I will have to settle with the replaceRE option.

Organizations spend thousands, even millions, of $ USD to develop and/or support a standard. Then they choose to selectively do something different. I’ve griped about RFC 5646 before, but at least it’s a standard.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.