Open azuddin opened 6 years ago
Same here....
You can see issue #56
Hey, you can workaround this by requiring the php file, and overwriting a JSON encoded string of the array parsed.
Thanks alot to the author of this package. However, this is my Temporary solution. Consider this:
localization:missing
.// @Author Kenan Masri
Artisan::command('localize', function () {
$locales = config('app.locales');
foreach ($locales as $locale) {
if ($locale == "en") continue;
$this->comment(" - Localize: " . $locale);
$file = base_path('resources/lang/'.$locale.".json");
if (file_exists($file.".php")) {
$array = require ( $file.".php" );
if (file_exists($file)) {
unlink($file);
}
$fp = fopen($file, 'w');
fwrite($fp, json_encode($array, JSON_UNESCAPED_UNICODE) );
fclose($fp);
$this->comment(" parsed \"resources/lang/".$locale.".json.php\" -> \"" . $locale . ".json\"");
} else {
$this->comment(" Not found: \"resources/lang/".$locale.".json.php\"");
}
}
})->describe('Generates the JSON language after using :missing');
// @Author Kenan Masri
Artisan::command('localize:missing', function () {
$locales = config('app.locales');
// Put the files for potsky/laravel-localization-helpers
foreach ($locales as $locale) {
if ($locale == "en") continue;
$this->comment(" - Localize: " . $locale);
$file = base_path('resources/lang/'.$locale.".json");
if (file_exists( $file.".php" )) {
copy($file.".php", $file);
$this->comment(" copy \"resources/lang/".$locale.".json.php\" -> \"" . $locale . ".json\"");
}
}
$this->comment("");
$this->comment(" - Running localization:missing -n");
// Find missings
$this->call('localization:missing', ['-n']);
// Hide the files for potsky/laravel/localization-helpers
$done = [];
foreach ($locales as $locale) {
if ($locale == "en") continue;
$this->comment(" - Localize: " . $locale);
$file = base_path('resources/lang/'.$locale.".json");
if (file_exists( $file )) {
if (file_exists($file.".php")) {
rename($file.".php", $file.".backup.php");
}
rename($file, $file.".php");
$this->comment(" rename \"resources/lang/".$locale.".json\" -> \"" . $locale . ".json.php\"");
$done[] = $locale;
} else {
$this->comment(" Not found: \"resources/lang/".$locale.".json\"");
}
}
$this->comment("");
foreach ($done as $l) {
$this->comment("You can edit the \"".$l.".json.php\" file safely.");
}
$this->comment("");
$this->comment("Tip: Generate JSON with the artisan command: \"localize\".");
})->describe('Generates the PHP sources to edit missing translations');
@potsky Sir, I don't know if it's useful. I hope so maybe you can think of an idea like this. Thanks!
i also received the same error. would be solution given by @knno is the solution ?
generated php code instead of json.