cncf / hugo-netlify-starter

Static website template for CNCF projects
https://cncf-hugo-starter.netlify.com/
Other
26 stars 16 forks source link

add i18n #106

Open kapunahelewong opened 2 years ago

kapunahelewong commented 2 years ago

I'm working on internationalization for our starter and it appears to be working, but could someone take a look and advise me on demonstrating it better? As you can see from the preview, it's defaulting to the English, which is good, but how do I display the list of languages and where should I reference those new partials?

 {{ partial "i18nlist.html" }}
 {{ partial "allLanguages.html" }}

I've been experimenting with the docs and a tutorial and I think I'm halfway there. Any feedback and pointers would be greatly appreciated. Thank you!!!

cc @celestehorgan @chalin @nate-double-u

kapunahelewong commented 2 years ago

Preview:

https://deploy-preview-106--cncf-hugo-starter.netlify.app

nate-double-u commented 2 years ago

This is how I tried to do it with Hugo using a folder based versioning system (like we use on CNI and etcd. Hugo normally uses a URL based versioning system, so this may still be helpful):

PR: https://github.com/nate-double-u/docsy-example/pull/1 Preview: https://deploy-preview-1--jolly-albattani-baa029.netlify.app/

nate-double-u commented 2 years ago

PR: nate-double-u/docsy-example#1 Preview: https://deploy-preview-1--jolly-albattani-baa029.netlify.app/

That PR is probably not super helpful as there's like 200+ files changed...

Here's a better preview link too since i disabled the versions menu on non-versioned pages: https://deploy-preview-1--jolly-albattani-baa029.netlify.app/docs/

The versioning is similar to how we do it in etcd.io

I'm not sure there is much of a difference now between my test code and the etcd.io code as what i was exploring was how to deal with the the extended language url when you have a default (which has no language id in the url - https://deploy-preview-1--jolly-albattani-baa029.netlify.app/docs/ ) , and a non default language (which needs the identifier - https://deploy-preview-1--jolly-albattani-baa029.netlify.app/no/docs/), which I believe got folded into the etcd.io code when we moved the English docs into content/en.

celestehorgan commented 2 years ago

@kapunahelewong I think you're on the right track, per Hugo's documentation. What I think @nate-double-u is alluding to in his comments is implmenting translation by content directory.

When localizing we usually prefer projects to use different subdirectories for each localization.

Can you add some test files to your pr, /content/en/blah.md and /content/fr/blah.md, to test this out? You may need to move all existing content into /content/en/ when you create it.

kapunahelewong commented 2 years ago

Thank you both! I've updated but how do I get the index to point to the correct file? The config.yaml has this:

menu:
  main:
    - name: Home
      url: /
      weight: 1
    - name: Documentation
      url: /en/docs/
      weight: 2

But the page that renders isn't picking up the _index.md in en or in content. 🤔

@celestehorgan @nate-double-u