-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated lang files contains an invalid JSON structure. #68
Comments
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.
// @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.
The text was updated successfully, but these errors were encountered: