I18n support for language-country code

Austrian :austria: and German :de: German differ, as reported an Austrian in pacollins/hugo-future-imperfect-slim#61.

However, Hugo doesn’t support language codes like de-at in defaultContentLanguage.

When you say it isn’t supported, what is happening exactly that indicates that?

Copied from https://github.com/pacollins/hugo-future-imperfect-slim/issues/61#issuecomment-522366409:

After experimenting, Hugo does not recognize de-at or at as a defaultContentLanguage.

Error: site config value "de-AT" for defaultContentLanguage does not match any language definition
Error: site config value "at" for defaultContentLanguage does not match any language definition

So this might be an issue to push further up the chain.

Hugo does support country-specific language codes.
Yet, the languageCode seems to set the language without a ‘sub-regional’ context only.

(The issue you are pointing to is theme-specific and can easily be solved, I guess.)

You can use the following:

languageCode: de-at

For a multilingual website you can use this:

defaultContentLanguage: de
    weight: 1
    languageCode: de-at

In your baseof.html you can use this:

<html lang="{{ .Site.LanguageCode }}">

If you go to http://localhost:1313/index.xml you will also find this line:

1 Like

That shows tests of de-AT and at, but what about de-at specifically. Does that work, or give an error?

Interpreted as site default language (English).

    languageCode        = "de-at"
    LanguageName        = "Deutsch (Österreich)"

<div id="content">
  {{ .Content }}
  <div class="contact-container">
    {{ if .Params.netlify }}
      <form name="contact" action="thank-you" netlify center width="300px">
    {{ else }}
      <form id="contact" action="//{{ .Params.emailService }}" method="post" center width="300px">
    {{ end }}
    <h4>{{ i18n "categories" }}</h4>
    <h4>{{ i18n "repliestext" .Params.contactanswertime }}</h4>
    <p>{{ .Params }}</p>
      <input placeholder="{{ with .Params.contactname }}{{ . }}{{ else }}Name{{ end }}" type="text" name="name" tabindex="1" required autofocus>
      <input placeholder="{{ with .Params.contactemail }}{{ . }}{{ else }}Email{{ end }}" type="email" name="_replyto" tabindex="2" required>
      <input placeholder="{{ with .Params.contactsubject }}{{ . }}{{ else }}Subject{{ end }}" type="text" name="_subject" tabindex="3" required>
      <textarea placeholder="{{ with .Params.contactmessage }}{{ . }}{{ else }}Message{{ end }}" name="message" tabindex="4" required></textarea>
      <input type="hidden" name="_language" value="{{ .Params.contactlang }}">
      <button name="submit" class="button" type="submit" id="contact-submit" tabindex="5">{{ i18n "submit" }}</button>
  other = "02-01-2006"
  one = "1 Minute"
  other = "{{ .Count }} Minuten"
  other = "Letzte Artikel"
  other = "Mehr erfahren"
  other = "Weiterlesen"
  other = "Kategorien"
  other = "Kategorie"
  other = "Tags"
  other = "Tag"
  other = "Unkategorisiert"
  other = "Teilen"
  other = "Über mich"
  other = "Mehr erfahren"
  one = "Antworten innerhalb von 1 Stunde."
  other = "Antworten innerhalb von {{ .Count }} Stunden."
  other = "Senden"
  other = "Seite nicht gefunden"
  other = "Entschuldigung, die Seite, die Sie suchen, ist leider nicht gibt."
  other = "Gehe zurück"
  other = "Blog"
  other = "Kontakt"
  other = "Nächste Seite"
  other = "Vorherige Seite"
  other = "Thema : <a href='https://github.com/pacollins/hugo-future-imperfect-slim' target='_blank' rel='noopener'>Hugo Future Imperfect Slim</a><br>Ein <a href='https://html5up.net/future-imperfect' target='_blank' rel='noopener'>HTML5 Port</a> | Unterstützt von: <a href='https://gohugo.io/' title='{{ .Site.Hugo.Version }}' target='_blank' rel='noopener'>Hugo</a>"

Did you add defaultContentLanguage and weight to config.toml mentioned above (above example is YAML)?

I’ve tried, though I think that shouldn’t be necessary since one might want something like

  1. :uk: Eng
  2. :us: Eng
  3. :cn: Simplified Chinese (zh-CN)
  4. :taiwan: Traditional Chinese (zh-TW)
  5. :hong_kong: Traditional Chinese (zh-HK)

Dropping support for any one of :cn:, :hong_kong: and :taiwan: can trigger sentiments of hundreds of netizens like: https://gitlab.com/gitlab-org/gitlab-ce/issues/60768

I’ve added <p>{{ .Lang }}</p> in the Go-HTML template for debug, as well as applying for suggested changes.

title = "Contact"
type = "contact"
netlify = false
emailservice = "formspree.io/example@email.com"
contactname = "Your name"
contactemail = "Your Email"
contactsubject = "Subject"
contactmessage = "Your Message"
contactlang = "en"
contactanswertime = 24

It seems that the German verison of the above file gets rendered since the form placeholder text is determined by content/contact/_index(.*).html.

The submit button text is missing despite nonempty German traslation for submit in the local file in my previous reply.

:tada: :taiwan: :v: I’m found the solution !

Thanks to the project Public Money Public Code.

# config.toml
  languageCode  = "zh-TW"
  languageName  = "正體中文(臺灣)"

While the file name should be foo.zh-tw.md in lower case for the language-country part.

1 Like