$kirby->router()->call($routePath, 'GET') returns the content in the wrong language

I have a multilingual website with the following structure:

/
    de/
        test/
    en/
        test/

Both test sites’ routes are virtual pages created in a plugin.

I use the static site generator plugin to generate the site.

When I run the generate.php, it creates the site in the correct language, but when I try to generate the site in the other language, it returns the content of the first language.

So I tried dumping the content in the generate plugin where it gets it from Kirby:

protected function _getRouteContent(string $routePath)
	{
		var_dump($routePath);
		if (!$routePath) {
			return null;
		}

		$routeResult = kirby()
			->router()
			->call($routePath, 'GET');

		var_dump($routeResult);

		if ($routeResult instanceof Page) {
			return $routeResult;
		}

		if ($routeResult instanceof \Kirby\Http\Response) {
			$routeResult = $routeResult->body();
		}

		return is_string($routeResult) ? $routeResult : null;
	}

It returns the right paths but not the correct content for the paths.

I also tried to dump the content of the $content = $page->content($currentLanguage); and it returns the correct data for the language. If I use $content = $page->content(); it returns the wrong content but only in the generated pages. If I start the Kirby router myself and test it in the browser, everything works.

So I read some more on the router stuff and found the LanguageRouter and tried to use it in the generate plugin: but the routes are empty:

	{
		var_dump($routePath);
		if (!$routePath) {
			return null;
		}
		var_dump($languageCode);

		$routeResult = kirby()
			->router()
			->call($routePath, 'GET');
		
		var_dump(kirby()
			->language($languageCode)
			->router()->routes());
		var_dump(kirby()
			->language($languageCode)
			->router()->call($routePath, 'GET'));
		var_dump(kirby()->router()->call($routePath, 'GET'));


		if ($routeResult instanceof Page) {
			return $routeResult;
		}

		if ($routeResult instanceof \Kirby\Http\Response) {
			$routeResult = $routeResult->body();
		}

		return is_string($routeResult) ? $routeResult : null;
	}

I have also created a demo repo for you to check it out: GitHub - dustsucker/SSG-Translation: SSG-Translation

It uses git submodules so you have to initialize them first:

git submodule init
git submodule update

Then you can run the generate.php and see the output.

In the test-plugin, you can see the routes for the pages and the content of the pages.

I hope you can help me with this problem.

Just had a quick look at the demo code, but that’s not a proper multilanguage site, while it has language definitions, the text files are missing the language extensions, so this won’t work.

I don’t understand this setup, why are there folders for German and English? Or what is that structure?