Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n function does not work in ExecuteAsTemplate #7070

Closed
reuixiy opened this issue Mar 19, 2020 · 3 comments
Closed

i18n function does not work in ExecuteAsTemplate #7070

reuixiy opened this issue Mar 19, 2020 · 3 comments
Labels
Milestone

Comments

@reuixiy
Copy link

reuixiy commented Mar 19, 2020

What version of Hugo are you using (hugo version)?

$ hugo version
Hugo Static Site Generator v0.67.1/extended linux/amd64 BuildDate: unknown

Does this issue reproduce with the latest release?

Yes


script.html

{{- $copy := resources.Get "js/copy.js" | resources.ExecuteAsTemplate "js/copy-rendered.js" . -}}

copy.js

const copyText = '{{ i18n "copy" }}';
const copiedText = '{{ i18n "copied" }}';

Live demo: https://io-oi.me/en/about/ (with Hugo v0.66.0)

Hover the code block, the text should be Copy instead of 复制.

Seems like a degradation? #6331

@reuixiy reuixiy changed the title i18n does not work in ExecuteAsTemplate in v. i18n does not work in ExecuteAsTemplate Mar 19, 2020
@reuixiy reuixiy changed the title i18n does not work in ExecuteAsTemplate i18n function does not work in ExecuteAsTemplate Mar 19, 2020
@bep bep added the Bug label Mar 20, 2020
@bep bep added this to the v0.68 milestone Mar 20, 2020
@bep bep removed the Bug label Mar 20, 2020
@bep
Copy link
Member

bep commented Mar 20, 2020

I fixed a bug in 0.67.1. Now we use all the arguments to ExecuteAs... when we create the cache key.

So:

 resources.ExecuteAsTemplate "js/copy-rendered.js" . 

There is the page (".") and the path (js/copy...).

The path is, however, language-agnostic (so to speak), so there is a "first win" situation here.

So, if you really want to create a JS per language, try:

...resources.ExecuteAsTemplate (printf "%s/js/copy-rendered.js" .Lang)  -}}

Also note that re my first comment above, it's not generally a great idea to pass the current page in as the context if you don't produce a "per page" resource (as you would execute the template x number of pages).

@bep bep closed this as completed Mar 20, 2020
@reuixiy
Copy link
Author

reuixiy commented Mar 21, 2020

Thanks a lot!

@github-actions
Copy link

github-actions bot commented Feb 5, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants