Skip to content
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

[WIP] Add experimental support for json language files to support strings #116

Merged
merged 2 commits into from
Oct 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class LangJsGenerator
*/
protected $messagesIncluded = [];

/**
* Name of the domain in which all string-translation should be stored under.
* More about string-translation: https://laravel.com/docs/master/localization#retrieving-translation-strings
*
* @var string
*/
protected $stringsDomain = 'strings';

/**
* Construct a new LangJsGenerator instance.
*
Expand Down Expand Up @@ -116,8 +124,8 @@ protected function getMessages()

foreach ($this->file->allFiles($path) as $file) {
$pathName = $file->getRelativePathName();

if ($this->file->extension($pathName) !== 'php') {
$extension = $this->file->extension($pathName);
if ($extension != 'php' && $extension != 'json') {
continue;
}

Expand All @@ -128,12 +136,19 @@ protected function getMessages()
$key = substr($pathName, 0, -4);
$key = str_replace('\\', '.', $key);
$key = str_replace('/', '.', $key);

if (starts_with($key, 'vendor')) {
$key = $this->getVendorKey($key);
}

$messages[$key] = include $path . DIRECTORY_SEPARATOR . $pathName;
$fullPath = $path.DIRECTORY_SEPARATOR.$pathName;
if ($extension == 'php') {
$messages[$key] = include $fullPath;
} else {
$key = $key.$this->stringsDomain;
$fileContent = file_get_contents($fullPath);
$messages[$key] = json_decode($fileContent, true);
}
}

$this->sortMessages($messages);
Expand Down