-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opengraph template locale- fallback to site's locale param #8296
Comments
This should be done because the Facebook documentation on that tag says "Defaults to en_US." - which is probably not what everyone wants as default if left empty. I would suggest:
|
I disagree. If, for example, a French-language site doesn't specify (forgets or doesn't know - or for whatever reason) a locale param on their site then they will specifically specify that their site is in American English. This would be bad. It'd be better to not specify it than specify the wrong value. REF: https://ogp.me/ |
"og:locale - The locale these tags are marked up in. Of the format language_TERRITORY. Default is en_US." I understand that as "if it's not set it is assumed en_US". Maybe add a warnf instead of the default tag so that people using that partial will know that something is going on? With a link to the resulting documentation or this issue here. |
I don't think it should add locale unless the user specifies it on the page or in the site config. It's not a required param. If you check Hugo's homepage with https://developers.facebook.com/tools/debug/?q=https%3A%2F%2Fgohugo.io%2F - it doesn't have any errors or warnings about the locale not being set. |
I am not saying you are wrong, I am saying if Hugos website would be Chinese, Facebook would think it's en_US due to not having a og:locale tag. If that template is touched why not make it perfect with a quick notice if it's not set up properly? |
Maybe a site scanning for Opengraph tags would fallback to the |
I am just suggesting ;) I am not using the internal templates myself - mostly because Hugo does create my site, not my HTML :) The thumbs up on the starting post still stands. |
So I looked over the current situation with multilingual mode. I believe the opengraph template has been left behind with all the updates to multilingual support. Open Graph wants the locale specified with as Using this config languageCode = "en-US"
defaultContentLanguage = "en_US"
[languages]
[languages.en_US]
title = "English site title"
[languages.es_ES]
title = "Spanish site title" You can then access <!-- layouts/_default/baseof.html -->
<head>
<!-- This translation -->
{{ with .Language }}<meta property="og:locale" meta="{{ .Language.Lang }}">{{ end }}
<!-- Other translations -->
{{ range .Translations }}
<meta property="og:locale:alternate" content="{{ .Language.Lang }}" />
{{ end }}
</head>
See docs Produces this result:
With the locale all lower case. <meta content="es_es">
<meta property="og:locale:alternate" content="en_us"> I'm not sure what's the best way to go about fixing this. Hugo supports 2 different ways of translating content. Content directory [languages]
[languages.es]
territory = "ES" |
Okay fooling around some more and I've come up with this solution. # config.toml
defaultContentLanguage = "en"
[languages]
[languages.en]
title = "English Site Title"
locale = "en_US"
[languages.es]
title = "Spanish Site Title"
locale = "es_ES" <!-- baseof.html or opengraph.html -->
{{ with .Language.Params.locale }}
<meta property="og:locale" content="{{ . }}">
{{ end }}
{{ range where .Translations "params" "locale" }}
<meta property="og:locale:alternate" content="{{ .Language.Params.locale }}" />
{{ end }} Produces: <meta property="og:locale" content="es_ES">
<meta property="og:locale:alternate" content="en_US"> This way it only adds languages with the locale specified. |
I think this should do:
Also, we should probably also add
We currently have Or something. |
@coliff any chance to review the changes? |
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. |
Sorry for the delayed response. I do agree that this needs to be fixed, and I do agree (as in the PR that was opened against this, #8306) that the configuration needs to live on With #8306 we would get: [languages]
[languages.en]
locale = "en_US" ==> lang="en"
locale="en_US" So, before we do this we need to determine if,
[languages]
[languages.en_US] /cc @jmooring |
Terminology
OverviewFrom a site author's perspective, Hugo's language key (e.g., the
When we read the language key from the site configuration, we convert it to lower case, and you do not have access to the original value from the templates. If I want an English language site localized to England, Wales, and Scotland, I must set the language key to
In some configurations the language key is just the language (e.g., And at some point in the distant past we added
Example configuration
Note that this configuration requires two translation files: RecommendationsNow (this issue):
Later:
Much later:
|
@coliff is this still unresolved? |
Changes: - Add tags per documentation - Prefer site.Title over site.Params.title - Plainify titles, tags, and descriptions - Add fallback values for locale - Fix pages related by series - Improve readability Closes gohugoio#8296 Closes gohugoio#8698 Closes gohugoio#8991 Closes gohugoio#9818 Closes gohugoio#9866 Closes gohugoio#10647 Co-authored by: tomy0000000 <[email protected]> Co-authored by: sean-au <[email protected]>
Changes: - Add tags per documentation - Prefer site.Title over site.Params.title - Plainify titles, tags, and descriptions - Add fallback values for locale - Fix pages related by series - Improve readability Closes gohugoio#8296 Closes gohugoio#8698 Closes gohugoio#8991 Closes gohugoio#9818 Closes gohugoio#9866 Closes gohugoio#10647 Co-authored-by: tomy0000000 <[email protected]> Co-authored-by: sean-au <[email protected]>
Changes: - Add tags per documentation - Prefer site.Title over site.Params.title - Plainify titles, tags, and descriptions - Add fallback values for locale - Fix pages related by series - Improve readability Closes gohugoio#8296 Closes gohugoio#8698 Closes gohugoio#8991 Closes gohugoio#9818 Closes gohugoio#9866 Closes gohugoio#10647 Co-authored-by: tomy0000000 <[email protected]> Co-authored-by: sean-au <[email protected]>
Changes: - Add tags per documentation - Prefer site.Title over site.Params.title - Plainify titles, tags, and descriptions - Add fallback values for locale - Fix pages related by series - Improve readability Closes gohugoio#8296 Closes gohugoio#8698 Closes gohugoio#8991 Closes gohugoio#9818 Closes gohugoio#9866 Closes gohugoio#10647 Co-authored-by: tomy0000000 <[email protected]> Co-authored-by: sean-au <[email protected]>
Changes: - Add tags per documentation - Prefer site.Title over site.Params.title - Plainify titles, tags, and descriptions - Add fallback values for locale - Fix pages related by series - Improve readability Closes #8296 Closes #8698 Closes #8991 Closes #9818 Closes #9866 Closes #10647 Co-authored-by: tomy0000000 <[email protected]> Co-authored-by: sean-au <[email protected]>
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Currently the built-in Opengraph template only adds the
<meta property="og:locale" content="" />
meta tag to a page if the locale param is in the frontmatter of the page. It'd be great if no param was specified in the frontmatter then it used the locale param in the sites config instead. It could make maintenance easier (if you have a 200-page site in a single language you only need to define the locale in the site config).Maybe something like this?
cc @djatwood
REF:
https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/opengraph.html
The text was updated successfully, but these errors were encountered: