1
0
This repository has been archived on 2023-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
dtux__avion-poeme/gestion/genere_lang.php

82 lines
1.8 KiB
PHP
Raw Normal View History

<?php
require_once '../session_init.php';
require_once 'config.inc.php';
$fisrt_line = false;
$fh = fopen("../lang/9mfo-traduction.csv", "r") or die("Can't open csv");
$fhIndex = fopen("../lang/lang.json", "w") or die("Can't open lang/lang.json");
fwrite($fhIndex, '{');
$first_line = true;
$first_column_line = true;
$first_object = true;
while( $line = fgets($fh))
{
$first_column = true;
$table = explode(';', $line);
$i =0;
foreach ( $table as $column )
{
$column = trim($column, " \n\r\t\v\0\"" );
echo $column . "=>";
if ($first_line == true)
{
echo "first_line =>";
if ( $first_column_line == true )
{
echo "first_column";
$first_column_line = false;
}else
{
$index = explode("/",$column);
echo "opening ../lang/" . $index[0];
$fhl[++$i] = fopen("../lang/" . $index[0], "w") or die("can't open lang/" . $index[0]);
fwrite($fhl[$i], '{');
fwrite($fhIndex, '"' . $index[0] . '":"' . $index[1] . '"');
}
echo EOL;
}else
{
if (!empty($fhIndex))
{
fclose($fhIndex);
}
echo "not first_line =>";
if ( $first_column == true )
{
$first_column = false;
$index = $column;
echo "first_column = ". $index . "=>";
}else
{
$i++;
if ($first_object == true) // insère la virgule
{
echo "first_object =>";
}else
{
echo "not first_object =>";
fwrite($fhl[$i], ", ");
}
fwrite($fhl[$i], '"' . $index . '":"' . $column .'"'); //écrit l'objet json
echo "writing " . '"' . $index . '":"' . $column .'"';
}
echo EOL;
}
echo EOL;
}
if ($first_line == false)
{
$first_object = false;
}
$first_line = false;
}
fclose($fh);
foreach( $fhl as $fhx)
{
fwrite($fhx, '}');
fclose($fhx);
}
?>