Kirby REST Api and Multilanguage

Hi!

I build a little REST Api like this https://getkirby.com/docs/cookbook/json and Using the JSON content api in combination with multilanguage sites

But what i have to do (i need the specific fields from my code) to get the correct JSON output for each language?

Here is an example, it works fine without multi language. For the URL ‘http://localhost:8000/investments/api’ i get this output:

"items": {
"pageTitle": "Investments",
"headline": "We provide you access to highly curated, top quartile, private equity funds."
},
"investments": [
{
"title": "Investment Committee",
"text": "The final hurdle every investment opportunity has to cross is our Investment Committee of seasoned industry experts. The committee's decisions are based on the members' deep industry knowledge and past experience, which complement our data-driven due diligence process."
},
{
"title": "Sourcing",
"text": "We keep close ties with academics, stay on top of the latest research and maintain tight relationships with industry insiders to get preferred access to the exclusive and robust investment opportunities."
},
{
"title": "Due Diligence",
"text": "We have a standardized approval process before investment opportunities go on our platform. We are completely independent and only select an offering if we feel comfortable investing our own money."
}
]
}

My example code:

<?php

header('Content-type: application/json; charset=utf-8');

$dataJSON = new stdClass;
$staticDataArray = new stdClass;
$investmentArray = array();

$data = $pages->find('investments');
$childData = $pages->find('investments')->children()->visible()->flip();

$staticDataArray->pageTitle = (string)$data->title();
$staticDataArray->headline = (string)$data->text();

foreach($childData as $investmentChild) {

  $investmentArray[] = array(
    'title' => (string)$investmentChild->title(),
    'text'  => (string)$investmentChild->text()
  );

}

$dataJSON->items = $staticDataArray;
$dataJSON->investments = $investmentArray;

echo json_encode($dataJSON);

?>

Does anyone know an idea to solve this?

You should get the standard language output at http://localhost:8000/investments/api and the non-standard language output at 'http://localhost:8000/lang-code/investments/api?

I’ve tried this. but this will not works. I got an blank site when i call for example http://localhost:8000/investments/{lang-code}/api

http://localhost:8000/investments/api gives me the correct output. But only when i do not configured the languages in config.php.
When i config the languages i get a blank page as well.

The URL is wrong, the lang-code must be directly after the domain:

default-lang (if you don’t use the language code for the default language): http://localhost:8000/investments/api
non-default-lang: http://localhost:8000/{lang-code}/investments/api

@texnixe I tried this at the first step. Blank page at the default page and when i use {en} the default.php will be rendered

Do your text files have the language extensions? api.de.txt etc.? No stray text files that don’t belong there?

Ah cool. That was it. I think i can work now in the case i need to do it. Thanks :slight_smile: