I have a multilingual page. I want to get the url of the other language page of the page I am on.
If you got everything set correctly, here is an example code to achieve what you want:
<div id="language">
{{ range site.Home.Translations }}
<a class="{{ .Lang }}" title="{{ .Lang }}" lang="{{ .Lang }}" hreflang="{{ .Lang }}" href="{{ .Permalink }}">
{{ .Lang }}
</a>
{{ end }}
</div>
Thank you, this helped me, but for example, for example, I am on the hello-world page, if I want to get the Turkish language of that page instantly at that moment, what will I do, this should be automatically.
What do you mean under “instantly” and “should be automatically”?
For example:
example.com/en/hello-world/
I am on the page of this page and there is a Turkish page and that page is this:
example.com/tr/merhaba-dunya/
When I am on the example.com/en/hello-world/
page, I want to link to example.com/tr/merhaba-dunya/
by saying that there is a Turkish version of this article at the bottom. And since I will put it in the footer.html
of each article, it should be automatic.
I wanted to say this.
Just change the code that I provided, whatever is in between <a>...</a>
like
<div id="language">
{{ range site.Home.Translations }}
<a class="{{ .Lang }}" title="{{ T "LanguageText" }}" lang="{{ .Lang }}" hreflang="{{ .Lang }}" href="{{ .Permalink }}">
{{ T "LanguageText" }}
</a>
{{ end }}
</div>
in \i18n\en.toml
[LanguageText]
other = "Read Turkish version of this article"
in \i18n\tr.toml
[LanguageText]
other = "Bu makalenin İngilizce sürümünü okuyun"
Unfortunately, it doesn’t work. I want to tell you this.
my current page: https://example.com/en/hello-world/
Other language page that matches this one: https://example.com/tr/merhaba-dunya/
When I go to https://example.com/en/hello-world/
, it should give me https://example.com/tr/merhaba-dunya/
as output.
the code you gave does not work. Thank you very much for your concern, though.
You need to connect /hello-world/
and /merhaba-dunya/
together using translationKey
.
Set in both markdown files, English and Turkish (in both that same as below):
translationKey: hello-world
{{- if .IsTranslated -}}
{{ range .Translations }}
{{ .Permalink }}
{{- end -}}
{{ end }}
I solved the problem with this code, thank you for your reply.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.