I18N - Country-codes as part of the URL

Hi everyone.

First of all I’d like to thank you for the great work you’re doing with Hugo.

We’re currently working on a big redesign and recode of one of the websites that’s already showcased in the Hugo Gallery.

We’re using another technology stack atop of Hugo which includes Docker, Pug templates, Less and a lot of custom code to make the Hugo experience easier for us and also allow us to extend it’s functionality without depending completely on Hugo’s development.

However we’ve been relying completely on Hugo for providing the i18n support, and it seems we’ve hit a wall.
We’ve been trying to find ways to use country-codes instead of language codes for the i18n system, e.g: DK instead of DA.

That means we’re trying to get something like:
- https://www.apple.com/dk/ <- Unsupported by Hugo
instead of:
- https://www.apple.com/da/ <- Supported very well

But as soon as we try to use ‘dk’ in the config file, and create the dk.yaml file in the i18n folder, we get the following error:

>> Error: Error building site: Failed to load translations in file "dk.yaml": no language found in "dk.yaml" >> Exited with code: 255. >> Error executing child process: Error: Process exited with code 255.

Now there’s a possibility that it’s all related to how https://github.com/nicksnyder/go-i18n works , but we’d just like to know the status, if it’s a known bug or if we’re doing something wrong…

One of the solutions that comes up in my mind is to move the translations in the data/ folder, like we’ve did before the v0.17 release, and just index them through the templates, but that might be quite a hassle, especially when switching between languages and when it comes to creating the paths manually for each .md file…

Can’t wait to hear your thoughts…
Thanks again.

What version of Hugo? I know we recently fixed some not optimal error messages in this department.

I refuse to believe that “dk” vs “da” should make a conceptual difference, so there must be something else going on. My guess would be that you changed site config to dk, but forgot to rename the language file.

Here’s the version we’re on:
Hugo Static Site Generator v0.21 linux/amd64 BuildDate: 2017-05-22T13:12:19Z

Just checked again to make sure, config is set to dk and the language file is also set right. A few months ago we’ve encountered the same issue with another website we’ve built but we just went ahead with ‘da’ instead of ‘dk’ in order to avoid tackling this issue.

We’ve also tried some other shortcodes in order to test it:

‘dk’ <- fails
’gb’ <- fails, should be Great Britain, but ‘uk’ works
’at’ <- fails, should be Austria

‘no’ <- works
’se’ <- works
’br’ <- works
’en-eu’ <- works, even if it’s not an official country code
’eu’ <- works, probably cause it detects it as the language ‘Basque’
‘oo’ <- fails, however it’s expected as this is not an official country code

By the way :slight_smile: thank you for the fast reply!

/cc @bogem

It’s an issue of https://github.com/nicksnyder/go-i18n, it can take language tags only from http://www.unicode.org/cldr/charts/28/supplemental/language_plural_rules.html.
I will open the issue there to hear the opinion of @nicksnyder.

1 Like

That sounds like a weird requirement – that we need to fix. I always assumed we could use the multilingual feature for non-languages.

Could you please send me a dk.yaml? At least some small part.

It is the language code that is relevant here, so just make something up.

I don’t need a random example, I just want to see a concrete config of @markcalvin 's custom translation files.
I want to see, how config files of @markcalvin look like, and know which plural category (one, other…) do they use for their translations.

Sorry for the late reply and thank you for looking into this.

We’ve never used the plural categories “one”, “other” in i18n cause we didn’t have the use case for it. We’re using the old i18n example that was featured in the docs website, with YAML not TOML ( which is featured now ), here’s an excerpt:

- id: string-hero-title
  translation: Title

- id: string-1
  translation: >
    This is an English YAML block comment that has a [link](http://google.com)
    
    Block comments can span multiple lines.

We have around ~600 strings like this both in the en.yaml and the dk.yaml which we then parse to markdown inside the templates.
The block comments are useful to us because we use https://crowdin.com edit the website’s content in place and translate it to other languages, so all the translation process is pretty much automated.

That also means that the YAML is always correctly structured because we use https://github.com/nodeca/js-yaml to move it back and forth.

Hi,
I have upgraded my website to hugo version Hugo Static Site Generator v0.29
And Im getting the following error

Error building site: Failed to load translations in file "de.yaml": failed to unmarshal de.yaml: yaml: unmarshal errors: line 1: cannot unmarshal !!seq into map[string]map[string]interface {}

Any idea?

The issue seems to be in the yaml file. Once I created a new file and copied the contents. It started working. Seems to be issue in file encoding? This is the changeset in the whole file. :roll_eyes::thinking: