Skip to content

Commit

Permalink
Use DIRECTORY_SEPARATOR and backup folder names
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeybob committed Oct 17, 2018
1 parent 89393c8 commit 0e662e9
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Console/TranslationDiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function handle()
}

// Define template path
$template_path = $resource_path . '/' . $this->argument('path');
$template_path = $resource_path . DIRECTORY_SEPARATOR . $this->argument('path');
if (!is_dir($template_path)) {
$this->error(sprintf('"%s" is neither a file nor a directory of resources.', $this->argument('path')));

Expand Down
2 changes: 1 addition & 1 deletion src/Console/TranslationUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function handle()
}

// Define resource path
$template_path = $resource_path . '/' . $this->argument('path');
$template_path = $resource_path . DIRECTORY_SEPARATOR . $this->argument('path');
if (!is_dir($template_path)) {
$this->error(sprintf('"%s" is neither a file nor a directory of resources.', $this->argument('path')));

Expand Down
6 changes: 3 additions & 3 deletions src/Facades/ResourceFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function isFileExist()
*/
public function getRelativePathname()
{
return str_replace($this->resource_path . '/', "", $this->path);
return str_replace($this->resource_path . DIRECTORY_SEPARATOR, "", $this->path);
}

/**
Expand All @@ -145,7 +145,7 @@ public function getRelativePathname()
*/
public function getLocalPathname()
{
return str_replace($this->resource_path . '/lang/', "", $this->path);
return str_replace($this->resource_path . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR, "", $this->path);
}

/**
Expand Down Expand Up @@ -281,7 +281,7 @@ public function save($noBackup = false)
*/
private function backup()
{
$filePath = $this->resource_path . '/lang/backup/' . $this->backupName . '/' . $this->getLocalPathname();
$filePath = $this->resource_path . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . $this->backupName . DIRECTORY_SEPARATOR . $this->getLocalPathname();
if (false === \File::isDirectory(dirname($filePath))) {
\File::makeDirectory(dirname($filePath), 0755, true);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Helpers/CommonHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ function __ab($key, $replace = [], $locale = null)

// Search translation in {locale}.json file
try {
$content = json_decode((new Filesystem)->get(resource_path('lang/' . app()->getLocale() . '.json')), true);
$content = json_decode((new Filesystem)->get(resource_path('lang' . DIRECTORY_SEPARATOR . app()->getLocale() . '.json')), true);
if (isset($content[$key])) {
return __($key, $replace, $locale);
}
} catch (\Exception $ex) {}

// Save to log file when translation does not exist for this $key
(new Filesystem)->append(
base_path(sprintf('storage/logs/%s', \Config::get('translator_log'))),
base_path(sprintf('storage' . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR . '%s', \Config::get('translator_log'))),
json_encode(array('message' => $key, 'locale' => app()->getLocale())) . "\n"
);

Expand Down Expand Up @@ -62,7 +62,7 @@ function trans_choice_ab($key, $number, array $replace = [], $locale = null)

// Save to log file when translation does not exist for this $key
(new Filesystem)->append(
base_path(sprintf('storage/logs/%s', \Config::get('translator_log'))),
base_path(sprintf('storage' . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR . '%s', \Config::get('translator_log'))),
json_encode(array('message' => $key, 'locale' => app()->getLocale())) . "\n"
);

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Locale implements Rule
public function passes($attribute, $value)
{
try {
$path = __DIR__ . '/../Storage/locales.json';
$path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Storage' . DIRECTORY_SEPARATOR . 'locales.json';
$content = json_decode((new Filesystem)->get($path), true);

return (true === array_key_exists($value, $content));
Expand Down
4 changes: 2 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function boot()
}

// Translations
$this->loadTranslationsFrom(__DIR__.'/Resources/lang', 'abtLang');
$this->loadTranslationsFrom(__DIR__. DIRECTORY_SEPARATOR .'Resources' . DIRECTORY_SEPARATOR . 'lang', 'abtLang');
}

/**
Expand All @@ -53,7 +53,7 @@ public function boot()
private function setConfig()
{
\Config::set('translator_log', 'translator.log');
\Config::set('resource_path', __DIR__ . '/Resources');
\Config::set('resource_path', __DIR__ . DIRECTORY_SEPARATOR . 'Resources');
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Services/TranslatorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public function __construct(
$this->template_path = $template_path;
$this->prefixes = $prefixes;
$this->dev = $dev;
$this->backupName = (null !== $backupName) ? $backupName : date('Y-m-d\TH:i:s');
// $this->backupName = (null !== $backupName) ? $backupName : date('Y-m-d\TH:i:s');
$this->backupName = (null !== $backupName) ? $backupName : date('U');

$this->loadResources();
if ('view' === $extract) {
Expand Down Expand Up @@ -156,7 +157,7 @@ public function getMessagesCount()
*
* @param string $hesh
*
* @return @return ResourceFacade
* @return ResourceFacade
*/
public function getResourceByHesh($hesh)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Traits/MessageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public function getNewMessages(bool $tableView = false) : array
public function addNewMessages()
{
foreach ($this->getNewMessages() as $message) {
$filePath = $this->resource_path . '/lang/' . $this->locale . '.json';
$filePath = $this->resource_path . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . $this->locale . '.json';
if (preg_match('/(^[a-zA-Z0-9]+)\.([\S].*)/', $message, $match)) {
$filePath = $this->resource_path . '/lang/' . $this->locale . '/' . $match[1] . '.php';
$filePath = $this->resource_path . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . $this->locale . DIRECTORY_SEPARATOR . $match[1] . '.php';
$message = $match[2];
}

Expand Down Expand Up @@ -132,7 +132,7 @@ private function extractUntrackedMessages()
{
$contents = [];
try {
$contents = explode(PHP_EOL, (new Filesystem)->get(base_path(sprintf('storage/logs/%s', \Config::get('translator_log')))));
$contents = explode(PHP_EOL, (new Filesystem)->get(base_path(sprintf('storage' . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR . '%s', \Config::get('translator_log')))));
} catch (\Exception $ex) {}

foreach ($contents as $content) {
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/ResourceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private function loadResources()
* resources/lang/{$locale}.json
*/
try {
$path = $this->resource_path . '/lang/' . $this->locale . '.json';
$path = $this->resource_path . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . $this->locale . '.json';
$content = (new Filesystem)->get($path);

$this->addResource($path, 'json');
Expand All @@ -56,7 +56,7 @@ private function loadResources()
* resources/lang/{$locale}/*.php
*/
try {
$path = $this->resource_path . '/lang/' . $this->locale . '/';
$path = $this->resource_path . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . $this->locale . DIRECTORY_SEPARATOR;
$finder = new Finder();
$finder->files()->name('*.php')->in($path);
foreach ($finder as $file) {
Expand Down

0 comments on commit 0e662e9

Please sign in to comment.