Undefined variable $lang in multilingual virtual page

In this guide, to provide multilingual translations for a virtual page, in the route’s action a $lang variable is passed:

               'action'  => function ($lang) {

… that is later used to render the page in the right lang:

                $page = Page::factory($data);

                site()->visit($page, $lang);

                return $page;

So I am trying to emulate that, but I am getting “Undefined variable: lang” on the site()->visit() line.

This is my code:

[
                'pattern' => '(en|es|ca)/privacy',
                'action'  => function ($lang) {
                    $data = [
                        'slug' => 'privacy',
                        'template' => 'privacy',
                        'translations' => [
                            'en' => [
                                'code' => 'en',
                                'content' => [
                                    'title' => 'Privacy',
                                    'text'  => site()->content('en')->privacy()
                                ]
                            ],
                            'es' => [
                                'code' => 'es',
                                'content' => [
                                    'title' => 'Privacidad',
                                    'text'  => site()->content('es')->privacy()
                                ]
                            ],
                            'ca' => [
                                'code' => 'ca',
                                'content' => [
                                    'title' => 'Privacitat',
                                    'text'  => site()->content('ca')->privacy()
                                ]
                            ],
                        ],
                    ];

                    $page = Page::factory($data);

                    site()->visit($page, $lang);

                    return $page;
                }
            ],

Forget it, human error.

I had two similar routes, one was not passing $lang on its action function.

Thanks