How To: Creating a file with default language?

How can i create a file with the content in the default language?

https://getkirby.com/docs/reference/objects/page/create-file

This doesn’t seem to work

            $user->createFile([
                'source'        => kirby()->root('site').'/payments/transaction.txt',
                'filename'      => $orderId . '.json',
                'template'      => 'transaction',
                'translations' => [
                    [
                        'code' => 'nl',
                        'content' => [
                            'order_id'      => $orderId,
                            'order_created' => $orderId,
                            'order_value'   => $orderValue,
                            'order_credits' => $orderCredits,
                            'order_status'  => $payment->status,
                            'user_id'       => $user->id(),
                            'ip_address'    => $ip,
                            'user_agent'    => $userAgent,
                        ],
                    ],
            ]
            ]);

what currently is working is this:

            $user->createFile([
                'source'        => kirby()->root('site').'/payments/transaction.txt',
                'filename'      => $orderId . '.json',
                'template'      => 'transaction',
                'content' => [
                    'order_id'      => $orderId,
                    'order_created' => $orderId,
                    'order_value'   => $orderValue,
                    'order_credits' => $orderCredits,
                    'order_status'  => $payment->status,
                    'user_id'       => $user->id(),
                    'ip_address'    => $ip,
                    'user_agent'    => $userAgent,
                ],
            ]);

Many thanks!!

Both versions should actually work for the default language, at least in my quick test they do.

The last version wil create a file with the current active language.

What is wrong with the first version then?

The first version will only work if the visit is in that language, in other languages it doesn’t create a file. I need to create a file with the default language no matter witch language is active for the user.

Something that will definitely work:

$file =  $user->createFile([
    'source'        => kirby()->root('site').'/payments/transaction.txt',
    'filename'      => $orderId . '.json',
    'template'      => 'transaction',
  ]);

if ($file) {
  $file->update([
    'content' => [
      'order_id'      => $orderId,
      'order_created' => $orderId,
      'order_value'   => $orderValue,
      'order_credits' => $orderCredits,
      'order_status'  => $payment->status,
      'user_id'       => $user->id(),
      'ip_address'    => $ip,
      'user_agent'    => $userAgent,
    ],
  ], 'en');
}

With this code it will create two language files one for the active language and one for the “default” language in my case ‘nl’ . I only need the default one.

CleanShot 2021-03-03 at 22.21.45

That’s strange, it doesn’t in my installation. Which Kirby version are you using? And where are you using this code?

I’m using it in the controller. kirby 3.5.1

After kirby update and some other updates this works now.

            $user->createFile([
                'source'        => kirby()->root('site').'/payments/transaction.txt',
                'filename'      => $orderId . '.json',
                'template'      => 'transaction',
                'content' => [
                    'order_id'      => $orderId,
                    'order_created' => $orderId,
                    'order_value'   => $orderValue,
                    'order_credits' => $orderCredits,
                    'order_status'  => $payment->status,
                    'user_id'       => $user->id(),
                    'ip_address'    => $ip,
                    'user_agent'    => $userAgent,
                ],
            ]);