Hi! I found various questions and answers on the matter, however, none of them seems to work.
Here’s my scenario: a form with a /thankyou/formdata.md embedded in other page(s).
---
title: '{{ CONTACTFORM.SENT_MESSAGE_PAGE_TITLE }}'
cache_enable: false
process:
twig: true
---
## {{ 'CONTACTFORM.SENT_MESSAGE_PAGE_TEXT'|t }}
Body gets translated, however title is not, regardless of the syntax used (when not throwing error).
Any advice?
Thanks!
@phmg701,
I found various questions and answers on the matter, however, none of them seems to work.
Before I repeat what others have done already…
- Which questions and answers have you found?
- For each: What doesn’t work, or doesn’t meet your needs?
I guess using multiple formdata.<lang>.md
has already been suggested?
@pamtbaau you’re right, sorry!
Various combinations of {{ “STRING” }} with or without |t filter, quotes, double quotes. I didn’t find a working combination for the frontmatter, but I could be wrong on interpreting syntax!
Yes, <lang>.md
could be a solution, yet title:
wouldn’t be a string of languages.yaml
which is my goal as form.md
is language-agnostic and fully translatable (page has no title as it is a non published page, I then embed the form elsewhere, very powerful Grav feature).
Thanks!
@phmg701, Did some playing and it seems the following is working:
- Fresh install of Grav 1.17.24
- Updated /user/config/system.yaml:
languages:
supported: [en, de]
pages:
frontmatter:
process_twig: true # Should the frontmatter be processed to replace Twig variables?
- Created Contact form in two languages + single thankyou page:
user/pages
├── 01.home
│ └── default.md
├── 02.typography
│ └── default.md
└── 03.contact
├── form.de.md
├── form.en.md
└── thankyou
└── formdata.md
03.contact/form.en.md + 03.contact/form.de.md---
title: Contact Form
form:
name: contact
fields:
name:
label: Name
type: text
buttons:
submit:
type: submit
value: Submit
process:
message: Thank you for getting in touch!
display: thankyou
---
formdata.md---
title: "{{ 'TITLE'|t }}"
process:
twig: true
---
## {{ 'CONTENT'|t }}
- Added translation to user/themes/quark/languages.yaml
en:
TITLE: Title-EN
CONTENT: Content-EN
de:
TITLE: Title-DE
CONTENT: Content-DE
- Browsed to localhost/en/contact, filled in the form and hit submit =>
Page title is English version + content is English version
- Browsed to localhost/de/contact, filled in the form and hit submit =>
Page title is German version + content is German version
Hope this is what you were looking for… If not, I’ve had some fun anyway.
2 Likes
Thank you! Works flawlessly!
I also managed to put a failsafe in the Twig template in case page title is missing, just in case…
Thanks again!
1 Like