This has been asked but, as far as I’ve seen, not throughly answered
When using page::create() or createChild() the page is always created in the default language as per this comment.
But as part of the $props parameter, we can include a ‘translations’ array, which in the reference page is described as Create the translations collection from an array.
This sounds as possibly related to providing translations of fields when programatically creating a page, so we can create the page on all the necessary languages at once, but I can’t find any documentation or examples on it.
No, Kirby only creates the page in the default language and for the translations you have to update the page. You will see that when you have a look at the source code for the method.
But… then the translations array does absolutely nothing on page creation ?
Is its purpose solely to be used in a posterior update as in the code above?
Also… if I am doing this in a loop, for regular pages with few fields, can I assume page creation is instantaneous, so for something like the code above I don’t have to worry about the page being created when running the foreach ?
Well, in the full code you would do this in a try/catch block to catch exceptions when the page cannot be created and maybe an additional if statement to make sure $newPage exists.
Well, in the example above, $newPage now contains the translations you can loop through, so while this doesn’t create the translations immediately, they are available in the variable.
Ok, but… usually the translations property contains a content object per each available language for that page is that correct ?
And what you are doing here is kind of squatting that variable with the content you will later use on the update.
If the above is correct It is perhaps a bit confusing that in page::create we can provide a translations array -which is usually the array that contains the page translations for a page that has translations in file- but in this case these translations are not applied to the created page, but just sit there.