TRADUCTION system for SLUG

Hi,

CONTEXT
My website is composed by 200 pages for each 3 languages, therefore 600 pages. To have exactly the same architecture between the 3 languages, I have no language text written in my layout but traduction ID only. And in my layouts and partial, I call (T .Params.). When I want to change contents (ex: change “_” to “-” in the slug chain), I don’t have to enter 600 times in each .md of each language. I only modify it very quickly my Excel files (with filters and research/replace options) where I have all my translations ID and the value for each languages. Then I export the CSV to the .toml format to fit and copy past it in the language files en.toml. It works perfectly in 95 % of case.

EXAMPLE WHICH WORKS
For instance, it perfectly works for Title. In the front matter of each of my pages, I put the ID I have created in the Excel file, as for instance Title: PAGE_NAME_TITLE. And in the baseof.html file, I call the translation of the parameter ‘Title’ :

    <title>
      {{ block "title" . }}
        {{ with (T .Params.Title) }}
          {{ . }}
        {{ end }}
      {{ end }}
    </title>

QUESTION FOR THE SLUG PARAMETER
My need is to do the same with the parameter Slug. How and where can I configurate (T .Params.slug) to call the traduction ID in the front matter ?

Hope it is clear enough.

Thanks a lot !!!

1 Like

Question to people who manage multilanguage websites.

How do you configure the slug ? Do you really writte it directely in the front matter of each of hundred of pages or do you have any tip to systemise the integration ?

This I can answer, yes, manually as I write new content.


My frontmatter looks like this (partial/truncated):

+++
title = ""
description = ""

date = "2022-04-07T17:53:01+00:00"                                          # manually adjust to local timezone

#aliases = [""]
slug = ""
translationKey = ""
+++

So for example:

en-ph

+++
title = "EN: Test post"
description = ""

date = "2022-04-07T17:53:01+08:00"                                          # manually adjust to local timezone

#aliases = [""]
slug = "test-post"
translationKey = "test-post-2022100"
+++

ko

+++
title = "KO: Test post"
description = ""

date = "2022-04-07T18:53:01+09:00"                                          # manually adjust to local timezone

#aliases = [""]
slug = "test-post"
translationKey = "test-post-2022100"
+++

ja

+++
title = "JA: Test post"
description = ""

date = "2022-04-07T18:53:01+09:00"                                          # manually adjust to local timezone

#aliases = [""]
slug = "test-post"
translationKey = "test-post-2022100"
+++

My permalink structure is:

blog = "/:slug-:year:yearday/"

The permalink for each will be:

  • en-ph (default): https://example.com/test-post-2022100/
  • ko: https://example.com/ko/test-post-2022100/
  • ja: https://example.com/ja/test-post-2022100/

If I need to do a mass edit, I use regex and use my editor’s search-and-replace feature. The editor will search all files in a certain folder and will replace all instances it finds even in closed files. You can do this in SublimeText and in VScode/VScodium.

I use this website regex101 to build and test my regex before I use it for mass search-and-replace. For VScode/VScodium, it uses JavaScript for its regex engine while SublimeText uses PCRE.

Here’s a sample regex, I recently had to change 「」 to 《》.

Another example, I recently started using linters and did not notice I made a mess of some URLs. Instead of reverting my repo back to before I started to use linters, I used regex to quickly do a mass fix.

1 Like

Thanks @techmagus for your feedbacks.

Are yours slugs the same for each language ?

In my case, I would like to personalise it for each language to enable a full experience for someone who speaks only the current language. Here an example for the homepage.

  • FR : .com/Accueil
  • EN : .com/Home
  • ES : .com/Inicio

Yep.

Ahh, that’s the setup I have in a site I scrapped.

To keep the translations working, you need: translationKey = ""

Set it the same for content translations so Hugo can see which is a translation of another content. Although I think you already have that frontmatter setting?