I want Kirby to put the correct language code inside a content file when an editor starts to translate a page.
Kirby names automatically new content files : “xxx.fr.txt” and “xxx.en.txt”. But it seems hard to get the same information INSIDE these files : to have a “Lang:” field that would be AUTOMATICALLY and correctly filled out.
What do I miss ?
I guess you mean when a translation is first saved?
Why do you need the information inside the content file?
You could store this information either via a hook or a page model, but be aware that Kirby has methods to find translations without the need to actually store this information.
Hi, pixelijn
I guess you mean when a translation is first saved?
Right. There is no new content file created until one save anything in a page to translate (a copy of the default language file).
You could store this information either via a hook or a page model,
What do you mean exactly ?
I need a field “Lang:” in a content file correctly and automatically fiiled out, without any action (like checkbox) by editors.
but be aware that Kirby has methods to find translations without the need to actually store this information.
I didn’t find any reliable and simple solutions yet. Or, as Kirby uses fields for everything, a field “Lang:” would be the simplest solution for various filterings, isn’t it ?
I think I still don’t really understand. At what point exactly do you want this content field to be stored? There is no hook for “no user action”. So you could either create an empty translation at the time the default language file is created (but if you do that, Kirby will no longer show the untranslated content of the default language but an empty page).
hi, pixelijn
what I need is :
• file “xxx.fr.txt” content :
Title: Bonjour
----
Lang: fr
----
Text: Ceci est un "Bonjour" en français.
----
• file “xxx.en.txt” content :
Title: Good morning
----
Lang: en
----
Text: This is a "Good morning" in English.
That’s all I need.
I’ve tried a field “Lang:” in xxx.yml blueprint :
Lang:
type: hidden
default: "{{kirby.language.code}}"
Unsurprisingly, this only works for the default language file (in my case French file).
When an editor starts a translation, he gets :
• file “xxx.en.txt” content :
Title: Good morning
----
Lang: fr
----
Text: This is a "Good morning" in English.
If Kirby knows to name correctly “xxx.fr.txt” and “xxx.en.txt”, it should be possible to get the equivalent in content files, shouldn’t it ?
Yes, I perfectly get what your desired result is. But a default value doesn’t help because the default is only set at page creation and no matter from which language you actually start, Kirby always creates the default content text file first.
That is the reason why you see the french language code in your English file (and why this is not a good idea).
What’s why I wrote “Unsurprisingly”.
Still looking for some advice.
I’m not aware of a way to achieve this.
It seems to be a mysterious side of Kirby.
Thanks anyway, pixelijn
If I were you, I’d stick with filtering by the presence of translation files.
Hi, Texnixe
Does Kirby use a filtering to achieve the correct naming of multilingual content files (“xxx.fr.txt”, “xxx.en.txt”, and so on) ?
If no, there should be a way to achieve what I need, shouldn’t it ?
I’m just unable to find it out myself