Skip to content
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

How to enable multilingual mode? #13

Closed
lizyn opened this issue Aug 25, 2017 · 5 comments
Closed

How to enable multilingual mode? #13

lizyn opened this issue Aug 25, 2017 · 5 comments

Comments

@lizyn
Copy link

lizyn commented Aug 25, 2017

I'm trying to open a bilingual blog recently. And please forgive my stupid request if you think it's against the minimal idea of this theme.

@lizyn lizyn changed the title How to toggle multilingual mode? How to enable multilingual mode? Aug 26, 2017
@yihui
Copy link
Owner

yihui commented Aug 26, 2017

It is not against the minimalist idea. Hugo has the multilingual mode and I believe you can use this mode, but it is probably not what you want for a bilingual blog: https://gohugo.io/content-management/multilingual/ Perhaps it is just that I don't understand it correctly, but I feel Hugo's multilingual mode is for translations of the same posts. If that is what you meant by "bilingual", please go ahead and use it. If you want two independent blogs with different languages, it is a little more complicated and I don't have time to explain how it may work -- you may study the source code of my own website: https://github.com/rbind/yihui (TL;DR my website is fairly complicated)

@lizyn
Copy link
Author

lizyn commented Aug 27, 2017

Sorry I didn't make it clear. What I want is a single blog, of which the main language is Chinese. And sometimes, for language practice purpose, I may translate some of the posts into English or simply write an independent English post. That's what I mean by bilingual. Perhaps I have used the wrong word.

I have checked https://gohugo.io/content-management/multilingual/ But I think this multilingual mode requires support from the theme level. Will look into it again when available.

@lizyn
Copy link
Author

lizyn commented Aug 28, 2017

I read through that page, and as instructed, created /partials/translations.html:

{{ if .IsTranslated }}
    {{ i18n "translations" }}
    {{ range .Translations }}
    <li><a href="{{ .Permalink }}">{{ .Lang }}</a></li>
    {{ end }}
{{ end }}

And then added a single line to /theme/hugo-xmin/layouts/partials/header.html to make it like this:

<body>
  <nav>
  <ul class="menu">
    {{ range .Site.Menus.main }}
    <li><a href="{{ .URL | relURL }}">{{ .Name }}</a></li>
    {{ end }}
    {{ partial "translations.html" . }}  # Added by me.
  </ul>
  <hr/>
  </nav>

At last, made some changes to /config.toml.

Not sure if that's the right way as I'm not very familiar with HTML and hugo, though the pages look good. I also wonder if there is another workaround that requires no change to files under the theme folder. Thanks for your time.

@lizyn
Copy link
Author

lizyn commented Aug 28, 2017

I made changes to header.html instead of header_custom.html because I prefer the language switcher to appear at the end of the menu.

menu

@yihui
Copy link
Owner

yihui commented Aug 28, 2017

That looks good to me.

@lizyn lizyn closed this as completed Aug 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants