gokarna-theme / gokarna-hugo

A minimal opinionated theme for Hugo
https://gokarna-hugo.netlify.app
GNU General Public License v3.0
357 stars 139 forks source link

Language of <h1 class="list-title">{{ .Name }}</h1> in partial "list.html" is not changing depending on the url ("es" or "en") #191

Closed felipebrunet closed 1 year ago

felipebrunet commented 1 year ago

Hi, I am having trouble at changing the language of the title of the posts section. When I click on "posts" header, a list of posts is displayed. However that list always shows as a title "Posts" despite the current language of the path. For example: The title name when accessing localhost:1313/en/posts/ is "Posts", that worked as expected. The title name when accessing localhost:1313/es/posts/ is "Posts", that did not work as expected. It should say "Posteos" IMHO.

In my config.toml file I have: For english: [[languages.en.menu.main]] name = "Posts" identifier = "posts" pre = "" url = "en/posts/" post = "" weight = 4

For spanish: [[languages.es.menu.main]] name = "Posteos" identifier = "posts" pre = "" url = "es/posts/" post = "" weight = 4

The "name" property when in spanish is "Posteos".

And in the "list.html" partial file, the following element :

<h1 class="list-title">{{ .Name }}</h1> 

refers to .Name

Shouldn't the name be "Posteos" when I am in the spanish url?

Maybe I am missing something, any help would be great. Thanks!!

felipebrunet commented 1 year ago

Solved it.

In that html element on list.html, I just had to make the following change:

Change this:

<h1 class="list-title">{{ .Name }}</h1> 

For this:

    <h1 class="list-title">{{ i18n .Name . }}</h1>

And create the i18N folder and add the following translated terms:

For the en.toml file

[Posts]
    other = 'Posts'
[Post]
    other = 'Post'
[Projects]
    other = 'Projects'
[Project]
    other = 'Project'

For the es.toml file

[Posts]
    other = 'Posteos'
[Post]
    other = 'Posteo'
[Projects]
    other = 'Proyectos'
[Project]
    other = 'Proyecto'

I am closing the issue myself.