Multilingual /ca/ca/ a bit confusing behaviour

Hugo Static Site Generator v0.51/extended darwin/amd64

Im not sure if this a bug, but I found it a bit confusing.
I have this content structure in my project.
— content
------ca
----------page
----------index.md
------de
----------page
----------index.md

and config
[languages]
[languages.ca]
contentDir = “content/ca/”
locale = “ca”
weight = 1
url = “/ca/”
[languages.de]
contentDir = “content/de/”
locale = “de”
weight = 2
url = “/de/”

When I’m trying to run the project I receive an error /ca/ca/page/s_101_1.png: no such file or directory
because of this code
{{range $index, $value := $resources }}
{{if in $value.Name $filename.image}}
<img src="{{(index ($resources) $index.MediaType)}};base64, {{ readFile (index ($resources $index).Relpermalink | base64encode)}}" /
{{end}}

So the point is when I’m trying to get some image from a content directory in a specific language and process with code written above I can’t do this because of contentDir and url concatenation. I tried to figure out how could I achieve it playing with url and contentDir. So if there is a concatenation and I would set contentDir to default than I could get image s_101_1.png by this path /ca/page/s_101_1.png.
I really like your project, sorry if I misunderstand something or have not done enough research to work it out. I just wanna use image processing with absLangURL.

This is very light for us to look into your issue.

Do you have a repo?

I’ve just updated part of the code, the place where Im receiving the error is {{readFile (index ($resources $index).Relpermalin | base64encode)}}. I’ll try to figure out something with an example code.

How you get $resources??
Do you use page bundles?
Dive deeper step by step - has the range elements? Do you get file names?
What do you have in $index and $value ? Let write it in the html file and check it out.

https://github.com/smiththesmith/hugo-multilingual here a repo example, really appreciate if you’ll help me to find some workaround for this problem.

Range will assign the current element to dot. So you don’t need to use index here. (It seems you can’t anyway)

Also, to grab all the resources, you can just call .Resources.

There is no more error with the following code, but I did not check the front.

{{ $resources := .Page.Resources }}

{{ range $index, $value := $resources }}
   {{if in $value.Name $filename.image}}
      <img src="data:{{ .MediaType }};base64,{{ .RelPermalink | base64Encode }}">
   {{end}}
{{ end }}

Thank you for your answer, but to convert file into bytecode I need to read the file first and I’m not able to do this. There is no error, but if you launch server and would follow page.html link there would be no preprocessed image.
data:image/png;base64,L3BhZ2UvaW1hZ2VfMS5wbmc= I receive this in the end

In this case:

<img src="data:{{ .MediaType }};base64,{{ .Content | base64Encode }}">
1 Like

Yes, regis was 5 minutes faster!

Thank you! You made my day!

1 Like