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

106 lines
2.3 KiB
PHP
Raw Normal View History

<?php
2021-04-29 10:32:58 +02:00
require_once '../session_init.php';
require_once 'config.inc.php';
2021-04-29 10:32:58 +02:00
if ( isset($_GET["ok"] ))
{
2021-04-29 10:32:58 +02:00
$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))
{
2021-04-29 10:32:58 +02:00
echo $line . EOLH;
$first_column = true;
$table = explode('|', $line);
$i =0;
foreach ( $table as $column )
{
2021-03-24 08:26:10 +01:00
2021-04-29 10:32:58 +02:00
$column = trim($column, " \n\r\t\0\"" );
2021-04-29 10:32:58 +02:00
if ($first_line == true)
{
//echo "first_line =>";
if ( $first_column_line == true )
2021-03-24 08:26:10 +01:00
{
2021-04-29 10:32:58 +02:00
//echo "first_column";
$first_column_line = false;
2021-03-24 08:26:10 +01:00
}else
{
2021-04-29 10:32:58 +02:00
$index = explode("/",$column);
echo "opening ../lang/" . $index[0] . EOLH;
$fhl[++$i] = fopen("../lang/" . $index[0], "wb") or die("can't open lang/" . $index[0]);
fwrite($fhl[$i], '{');
if ( $first_column == true )
{
$first_column = false;
}else
{
fwrite($fhIndex, ",");
}
fwrite($fhIndex, '"' . $index[0] . '":"' . $index[1] . '"');
2021-03-24 08:26:10 +01:00
}
2021-04-29 10:32:58 +02:00
echo EOLH;
}else
{
2021-04-29 10:32:58 +02:00
if (!empty($fhIndex))
{
2021-04-29 10:32:58 +02:00
fwrite($fhIndex, '}');
fclose($fhIndex);
unset($fhIndex);
}
2021-04-29 10:32:58 +02:00
//echo "not first_line =>";
if ( $first_column == true )
{
$first_column = false;
$index = $column;
//echo "first_column = ". $index . "=>";
}else
{
$i++;
if ($first_object == false) // insère la virgule
{
//echo "not first_object =>";
fwrite($fhl[$i], ", ");
}
$text = '"' . $index . '":"' . $column .'"';
fwrite($fhl[$i], $text ); //écrit l'objet json
echo "writing ***" . $text .'***' . EOLH;
fflush($fhl[$i]);
2021-04-07 21:08:08 +02:00
2021-04-29 10:32:58 +02:00
}
echo EOLH;
}
2021-04-29 10:32:58 +02:00
//echo EOLH;
}
2021-04-29 10:32:58 +02:00
if ($first_line == false)
{
$first_object = false;
}
$first_line = false;
}
2021-04-29 10:32:58 +02:00
fclose($fh);
foreach( $fhl as $fhx)
{
2021-04-29 10:32:58 +02:00
fwrite($fhx, '}');
fclose($fhx);
}
$fh = fopen("lang/lang.json","r");
$str = fgets($fh);
fclose($fh);
$lang = json_decode( $str, true);
foreach ($lang as $key => $value)
{
getLang( $key );
print $key;
print json_last_error_msg() .EOL;
}
}
?>