How to set the lang when creating a page programmatically?
Permalink
Hi,
I use a CSV file to create articles programmatically in Concrete5.
The website is multilingual so I need to set a local (available in the CSV file) info when creating the page.
How to set the local info in the database programmatically?
At the moment, this is my script:
```<?php
$data = [];
$datacsv = [];
$row = 0;
if (($handle = fopen("/path/to/articles.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
$datacsv[$row]['Date'] = $data[1];
$datacsv[$row]['Title'] = $data[2];
$datacsv[$row]['Content'] = $data[3];
$datacsv[$row]['Language Code'] = $data[4];
}
$row++;
}
//fclose($handle);
unset($datacsv[0]);
}
foreach ( $datacsv as $key => $value ) {
$parentPage = \Page::getByPath('/actualites-1');
$pageType = \PageType::getByHandle('actualite');
$template = \PageTemplate::getByHandle('full');
$entry = $parentPage->add($pageType, array(
'cName' => $value['Title'],
'cDescription' => $value['Content'],
'cContent' => $value['Content'],
'cHandle' => 'actualite-' . rand(1, 1000) . '-' . $key,
// How to set the local info ???????????
), $template);
}
```
Thanks for your help and advice :-)
I use a CSV file to create articles programmatically in Concrete5.
The website is multilingual so I need to set a local (available in the CSV file) info when creating the page.
How to set the local info in the database programmatically?
At the moment, this is my script:
```<?php
$data = [];
$datacsv = [];
$row = 0;
if (($handle = fopen("/path/to/articles.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
$datacsv[$row]['Date'] = $data[1];
$datacsv[$row]['Title'] = $data[2];
$datacsv[$row]['Content'] = $data[3];
$datacsv[$row]['Language Code'] = $data[4];
}
$row++;
}
//fclose($handle);
unset($datacsv[0]);
}
foreach ( $datacsv as $key => $value ) {
$parentPage = \Page::getByPath('/actualites-1');
$pageType = \PageType::getByHandle('actualite');
$template = \PageTemplate::getByHandle('full');
$entry = $parentPage->add($pageType, array(
'cName' => $value['Title'],
'cDescription' => $value['Content'],
'cContent' => $value['Content'],
'cHandle' => 'actualite-' . rand(1, 1000) . '-' . $key,
// How to set the local info ???????????
), $template);
}
```
Thanks for your help and advice :-)