mivinci / hugo-theme-minima

A clean and minimal Hugo theme.
https://mivinci.github.io/hugo-theme-minima
MIT License
130 stars 37 forks source link

How to add a language selection menu? #32

Closed memclutter closed 1 year ago

memclutter commented 1 year ago

I will have two languages, let's say Chinese and English. I added languages and translations to the configuration. Added two articles for an example with a different language.

And how can I display the language change in the template now?

mivinci commented 1 year ago

Can you show me what you've modified in the configuration?

memclutter commented 1 year ago
baseURL = "https://memclutter.me"
languageCode = "en-us"
title = "memclutter site"
copyright = "© memclutter 2022"
googleAnalytics = ""

# paginate decides the number of the newest posts
# that'll be shown on the home page.
paginate = 6

# theme is the name of the hugo theme you're gonna use,
# `hugo-theme-minima` is put here only for debuging,
# just name it what's under your theme directory.
theme = "minima"

# i18n
defaultContentLanguage = "en"
[languages]

  [languages.en]
  title = 'memclutter site'
  weight = 1

  [languages.ru]
  title = 'memcluter'
  weight = 2
    [languages.ru.author]
    slogon = ""
    description = "Backend/DevOps/SRE с опытом более 8 лет"
    [languages.ru.params]
    iam = ""
    recent = "Свежее"
    older = "Старое"
    [[languages.ru.menu.main]]
    name = "Главная"
    url = "/"
    weight = 1
    [[languages.ru.menu.main]]
    name = "Категории"
    url = "/categories"
    weight = 2
    [[languages.ru.menu.main]]
    name = "Обо мне"
    url = "/about"
    weight = 4

# Author has some of your information to be shown on the home page.
[author]
name = "memclutter"
slogon = "not war, write code, make things"
description = "Backend/DevOps/SRE engineer with +8 years experience"

[params]
# iam is the beginning words of your self-introduction.
iam = "I am"
# The subtitle will be shown after the title of your blog site.
# e.g. "title - subtitle".
subtitle = ""
# Comment decides the comment plugin to be used on your blog site, 
# e.g. disqus, utterances, ovo.
comment = "utterances"
# Timeformat, no matter what format to use, make it the second day of Jan. 2006
timeformat = "Jan 02, 2006"
# switch for turning on/off lights.
switch = ["🌚", "🌝"]
# default theme. e.g. light, dark, system
defaultTheme = "dark"
# If set true, date of posts will be shown in the homepage.
displayDate = true
# If set true, users can select text from your post.
selectable = true
# Custom global font. notice: `globalFontFamily` won't be working
# on texts in some special positions like on titles
globalFontFamily = ""
# If set true, all your posts will use the chosen comment plugin
# except those with a `comment: false` in their front-matter
commentOnAllPosts = true
# toc decides the shape of the toc button. e.g. default, lines, bar
toc = "lines"

recent = "Recent Posts"
older = "Older Posts"

# Disqus configuration
[params.disqus]
shortname = "hugo-minima"

# Utterances configuration
# Full doc's at https://utteranc.es
# **notice**: if you're going to use utterances, you must change the 
# `repo` to your own repo address that stores comments on your site
[params.utterances]
repo = "mivinci/hugo-theme-minima"
issueTerm = "pathname"

# **deprecated**
# OvO is a comment plugin written by the author of Minima.
# It is enabled when params.comment is set "ovo". You can
# have a live view on https://ovo.js.org. If you are using 
# disqus or utterance, just ignore this.
[params.ovo]
server = ""
placeholder = ""

# Params.social is an array containing your social network accounts,
# Each has a lowercase name, a svg formatted icon and a url to the 
# webpage of your account. They will be shown at the bottom of every
# page of your blog. 
# Be sure the svgs you use must have both its width and its height
# set 18. If you don't wanna put the svg code in this config file, 
# since they are too long, you can instead save them to the 
# `data/svg.toml` file under the root directory of your blog. 
# in that file, each line must be formatted as `name = '<svg>'`
# where `<svg>` is the svg code.
[[params.social]]
name = "github"  
url = "https://github.com/memclutter"
svg = ""
[[params.social]]
name = "linkedin"
url = "https://linkedin/in/memclutter"
svg = ""
[[params.social]]
name = "facebook"
url = "https://facebook.com/memclutter"
svg = ""
[[params.social]]
name = "twitter"
url = "https://twitter.com/memclutter"
svg = ""
[[params.social]]
name = "rss"
url = "/index.xml"
svg = ""

# If set, titles and links of the topk newest posts extracted from 
# the feeds will be displayed in the home page. Note that the feeds
# providers have to make their 'Access-Control-Allow-Origin' contain
# your domain, otherwise the feeds cannot be fetched.
# [params.friends]
# feeds = ["https://h.xjj.pub/index.xml"]
# topk = 3
# title = "Friends' Posts"
# proxy = "" # reserved

# Menu.main is an array that's used to decide what entries can be shown
# on the navigator of yur blog. You can use a weight to make them ordered.
[[menu.main]]
name = "Home"
url = "/"
weight = 1
[[menu.main]]
name = "Categories"
url = "/categories"
weight = 2
[[menu.main]]
name = "About"
url = "/about"
weight = 4

# You can classify your posts by setting taxanomies in the front matter
# e.g.
#     categories = ["dev"]
#     series = ["Building an RPC server"]
#     tags = ["hugo", "golang"]
# A little suggestion: one post belongs to one series or one category or multiple tags.
[taxonomies]
category = "categories"
tag = "tags"
series = "series"

# Fields below make sure all the codes in a post are
# highlighted correctly, so better not edit them.
[markup.highlight]
lineNos = true
noClasses = false
memclutter commented 1 year ago

it seems that there is simply no output of the language change widget in header.html. I correctly understand that it is necessary to redefine the template and add links?

I also added a pull request in which I corrected the display of links in the main menu #34

mivinci commented 1 year ago

I'm sorry that I've just got time to check this out. It looks like your PR works. I didn't figure out how to correctly add support for i18n when I made this theme so thanks so much for fixing it, bro.