Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Console/Commands/ListMissingTranslationKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function handle()
// check whether or not there are any missing translations
$empty = true;
foreach ($missingTranslations as $language => $values) {
if (!empty($values)) {
if (! empty($values)) {
$empty = false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Console/Commands/SynchroniseTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function handle()
else {
$this->fromDriver = $this->anticipate(__('translation::translation.prompt_from_driver'), $this->drivers);

if (!in_array($this->fromDriver, $this->drivers)) {
if (! in_array($this->fromDriver, $this->drivers)) {
return $this->error(__('translation::translation.invalid_driver'));
}
}
Expand All @@ -61,7 +61,7 @@ public function handle()
else {
$this->toDriver = $this->anticipate(__('translation::translation.prompt_to_driver'), $this->drivers);

if (!in_array($this->toDriver, $this->drivers)) {
if (! in_array($this->toDriver, $this->drivers)) {
return $this->error(__('translation::translation.invalid_driver'));
}
}
Expand All @@ -86,7 +86,7 @@ public function handle()
else {
$language = $this->anticipate(__('translation::translation.prompt_language_if_any'), $languages);

if ($language && !in_array($language, $languages)) {
if ($language && ! in_array($language, $languages)) {
return $this->error(__('translation::translation.invalid_language'));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Factories/TranslationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace JoeDixon\Translation\Database\Factories;

use JoeDixon\Translation\Language;
use Illuminate\Database\Eloquent\Factories\Factory;
use JoeDixon\Translation\Language;
use JoeDixon\Translation\Translation;

class TranslationFactory extends Factory
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Database/InteractsWithShortKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function allShortKeyGroupsFor(string $language): Collection
*/
public function addShortKeyTranslation($language, $group, $key, $value = ''): void
{
if (!$this->languageExists($language)) {
if (! $this->languageExists($language)) {
$this->addLanguage($language);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Database/InteractsWithStringKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function allStringKeyTranslationsFor(string $language): Collection
*/
public function addStringKeyTranslation($language, $vendor, $key, $value = ''): void
{
if (!$this->languageExists($language)) {
if (! $this->languageExists($language)) {
$this->addLanguage($language);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Drivers/File/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function addLanguage(string $language, ?string $name = null): void
throw new LanguageExistsException(__('translation::errors.language_exists', ['language' => $language]));
}

$this->disk->makeDirectory("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . "$language");
if (!$this->disk->exists("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . "{$language}.json")) {
$this->disk->makeDirectory("{$this->languageFilesPath}".DIRECTORY_SEPARATOR."$language");
if (! $this->disk->exists("{$this->languageFilesPath}".DIRECTORY_SEPARATOR."{$language}.json")) {
$this->saveStringKeyTranslations($language, collect(['string' => collect()]));
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/Drivers/File/InteractsWithShortKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace JoeDixon\Translation\Drivers\File;

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

trait InteractsWithShortKeys
{
Expand All @@ -17,7 +17,7 @@ public function allShortKeyTranslationsFor(string $language): Collection
// here we check if the path contains 'vendor' as these will be the
// files which need namespacing
if (Str::contains($group->getPathname(), 'vendor')) {
$vendor = Str::before(Str::after($group->getPathname(), 'vendor' . DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR);
$vendor = Str::before(Str::after($group->getPathname(), 'vendor'.DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR);

return ["{$vendor}::{$group->getBasename('.php')}" => new Collection($this->disk->getRequire($group->getPathname()))];
}
Expand All @@ -33,7 +33,7 @@ public function allShortKeyGroupsFor(string $language): Collection
{
return $this->allShortKeyFilesFor($language)->map(function ($file) {
if (Str::contains($file->getPathname(), 'vendor')) {
$vendor = Str::before(Str::after($file->getPathname(), 'vendor' . DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR);
$vendor = Str::before(Str::after($file->getPathname(), 'vendor'.DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR);

return "{$vendor}::{$file->getBasename('.php')}";
}
Expand All @@ -47,14 +47,14 @@ public function allShortKeyGroupsFor(string $language): Collection
*/
public function addShortKeyTranslation(string $language, string $group, string $key, string $value = ''): void
{
if (!$this->languageExists($language)) {
if (! $this->languageExists($language)) {
$this->addLanguage($language);
}

$translations = $this->allShortKeyTranslationsFor($language);

// does the group exist? If not, create it.
if (!$translations->keys()->contains($group)) {
if (! $translations->keys()->contains($group)) {
$translations->put($group, collect());
}

Expand All @@ -78,7 +78,7 @@ protected function addShortKeyGroup(string $language, string $group): void
*/
protected function allShortKeyFilesFor(string $language): Collection
{
$groups = new Collection($this->disk->allFiles("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . "{$language}"));
$groups = new Collection($this->disk->allFiles("{$this->languageFilesPath}".DIRECTORY_SEPARATOR."{$language}"));
// namespaced files reside in the vendor directory so we'll grab these
// the `getVendorGroupFileFor` method
$groups = $groups->merge($this->allVendorShortKeyFilesFor($language));
Expand All @@ -91,17 +91,17 @@ protected function allShortKeyFilesFor(string $language): Collection
*/
protected function allVendorShortKeyFilesFor(string $language): ?Collection
{
if (!$this->disk->exists("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . 'vendor')) {
if (! $this->disk->exists("{$this->languageFilesPath}".DIRECTORY_SEPARATOR.'vendor')) {
return null;
}

$vendorGroups = [];
foreach ($this->disk->directories("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . 'vendor') as $vendor) {
foreach ($this->disk->directories("{$this->languageFilesPath}".DIRECTORY_SEPARATOR.'vendor') as $vendor) {
$vendor = Arr::last(explode(DIRECTORY_SEPARATOR, $vendor));
if (!$this->disk->exists("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . "{$vendor}" . DIRECTORY_SEPARATOR . "{$language}")) {
if (! $this->disk->exists("{$this->languageFilesPath}".DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR."{$vendor}".DIRECTORY_SEPARATOR."{$language}")) {
array_push($vendorGroups, []);
} else {
array_push($vendorGroups, $this->disk->allFiles("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . "{$vendor}" . DIRECTORY_SEPARATOR . "{$language}"));
array_push($vendorGroups, $this->disk->allFiles("{$this->languageFilesPath}".DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR."{$vendor}".DIRECTORY_SEPARATOR."{$language}"));
}
}

Expand All @@ -121,7 +121,7 @@ protected function saveShortKeyTranslations(string $language, string $group, Col
return;
}

$this->disk->put("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . "{$language}" . DIRECTORY_SEPARATOR . "{$group}.php", "<?php\n\nreturn " . var_export($translations->toArray(), true) . ';' . \PHP_EOL);
$this->disk->put("{$this->languageFilesPath}".DIRECTORY_SEPARATOR."{$language}".DIRECTORY_SEPARATOR."{$group}.php", "<?php\n\nreturn ".var_export($translations->toArray(), true).';'.\PHP_EOL);
}

/**
Expand All @@ -130,12 +130,12 @@ protected function saveShortKeyTranslations(string $language, string $group, Col
protected function saveNamespacedShortKeyTranslations(string $language, string $group, Collection $translations): void
{
[$namespace, $group] = explode('::', $group);
$directory = "{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . "{$namespace}" . DIRECTORY_SEPARATOR . "{$language}";
$directory = "{$this->languageFilesPath}".DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR."{$namespace}".DIRECTORY_SEPARATOR."{$language}";

if (!$this->disk->exists($directory)) {
if (! $this->disk->exists($directory)) {
$this->disk->makeDirectory($directory, 0755, true);
}

$this->disk->put("$directory" . DIRECTORY_SEPARATOR . "{$group}.php", "<?php\n\nreturn " . var_export($translations->toArray(), true) . ';' . \PHP_EOL);
$this->disk->put("$directory".DIRECTORY_SEPARATOR."{$group}.php", "<?php\n\nreturn ".var_export($translations->toArray(), true).';'.\PHP_EOL);
}
}
10 changes: 5 additions & 5 deletions src/Drivers/File/InteractsWithStringKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace JoeDixon\Translation\Drivers\File;

use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

trait InteractsWithStringKeys
{
Expand All @@ -18,7 +18,7 @@ public function allStringKeyTranslationsFor(string $language): Collection
return strpos($file, "{$language}.json");
})->flatMap(function ($file) {
if (strpos($file->getPathname(), 'vendor')) {
$vendor = Str::before(Str::after($file->getPathname(), 'vendor' . DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR);
$vendor = Str::before(Str::after($file->getPathname(), 'vendor'.DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR);

return ["{$vendor}::string" => new Collection(json_decode($this->disk->get($file), true))];
}
Expand All @@ -32,7 +32,7 @@ public function allStringKeyTranslationsFor(string $language): Collection
*/
public function addStringKeyTranslation(string $language, string $vendor, string $key, string $value = ''): void
{
if (!$this->languageExists($language)) {
if (! $this->languageExists($language)) {
$this->addLanguage($language);
}

Expand All @@ -50,9 +50,9 @@ private function saveStringKeyTranslations(string $language, Collection $transla
{
foreach ($translations as $group => $translation) {
$vendor = Str::before($group, '::string');
$languageFilePath = $vendor !== 'string' ? 'vendor' . DIRECTORY_SEPARATOR . "{$vendor}" . DIRECTORY_SEPARATOR . "{$language}.json" : "{$language}.json";
$languageFilePath = $vendor !== 'string' ? 'vendor'.DIRECTORY_SEPARATOR."{$vendor}".DIRECTORY_SEPARATOR."{$language}.json" : "{$language}.json";
$this->disk->put(
"{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . "{$languageFilePath}",
"{$this->languageFilesPath}".DIRECTORY_SEPARATOR."{$languageFilePath}",
json_encode((object) $translations->get($group), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
);
}
Expand Down
24 changes: 12 additions & 12 deletions src/Drivers/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,52 @@ abstract class Translation
/**
* Get all languages.
*/
public abstract function allLanguages(): Collection;
abstract public function allLanguages(): Collection;

/**
* Determine whether the given language exists.
*/
public abstract function languageExists(string $language): bool;
abstract public function languageExists(string $language): bool;

/**
* Add a new language.
*/
public abstract function addLanguage(string $language, ?string $name = null): void;
abstract public function addLanguage(string $language, ?string $name = null): void;

/**
* Get all translations.
*/
public abstract function allTranslations(): Collection;
abstract public function allTranslations(): Collection;

/**
* Get all translations for a given language.
*/
public abstract function allTranslationsFor(string $language): Collection;
abstract public function allTranslationsFor(string $language): Collection;

/**
* Get short key translations for a given language.
*/
public abstract function allShortKeyTranslationsFor(string $language): Collection;
abstract public function allShortKeyTranslationsFor(string $language): Collection;

/**
* Get all the short key groups for a given language.
*/
public abstract function allShortKeyGroupsFor(string $language): Collection;
abstract public function allShortKeyGroupsFor(string $language): Collection;

/**
* Add a short key translation.
*/
public abstract function addShortKeyTranslation(string $language, string $group, string $key, string $value = ''): void;
abstract public function addShortKeyTranslation(string $language, string $group, string $key, string $value = ''): void;

/**
* Get string key translations for a given language.
*/
public abstract function allStringKeyTranslationsFor(string $language): Collection;
abstract public function allStringKeyTranslationsFor(string $language): Collection;

/**
* Add a string key translation.
*/
public abstract function addStringKeyTranslation(string $language, string $vendor, string $key, string $value = ''): void;
abstract public function addStringKeyTranslation(string $language, string $vendor, string $key, string $value = ''): void;

/**
* Find all of the translations in the app without translation for a given language.
Expand Down Expand Up @@ -124,7 +124,7 @@ public function getSourceLanguageTranslationsWith(string $language): Collection
public function filterTranslationsFor(string $language, ?string $filter): Collection
{
$allTranslations = $this->getSourceLanguageTranslationsWith(($language));
if (!$filter) {
if (! $filter) {
return $allTranslations;
}

Expand All @@ -142,7 +142,7 @@ public function filterTranslationsFor(string $language, ?string $filter): Collec
public function add(Request $request, $language, $isGroupTranslation)
{
$namespace = $request->has('namespace') && $request->get('namespace') ? "{$request->get('namespace')}::" : '';
$group = $namespace . $request->get('group');
$group = $namespace.$request->get('group');
$key = $request->get('key');
$value = $request->get('value') ?: '';

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/LanguageTranslationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function store(TranslationRequest $request, $language)

public function update(Request $request, $language)
{
$isGroupTranslation = !Str::contains($request->get('group'), 'single');
$isGroupTranslation = ! Str::contains($request->get('group'), 'single');

$this->translation->add($request, $language, $isGroupTranslation);

Expand Down
2 changes: 1 addition & 1 deletion src/TranslationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function resolve()
$driverResolver = Str::studly($driver);
$method = "resolve{$driverResolver}Driver";

if (!method_exists($this, $method)) {
if (! method_exists($this, $method)) {
throw new \InvalidArgumentException("Invalid driver [$driver]");
}

Expand Down
20 changes: 10 additions & 10 deletions src/TranslationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public function register()
*/
private function loadViews()
{
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'translation');
$this->loadViewsFrom(__DIR__.'/../resources/views', 'translation');

$this->publishes([
__DIR__ . '/../resources/views' => resource_path('views/vendor/translation'),
__DIR__.'/../resources/views' => resource_path('views/vendor/translation'),
]);
}

Expand All @@ -71,7 +71,7 @@ private function loadViews()
*/
private function registerRoutes()
{
$this->loadRoutesFrom(__DIR__ . '/../routes/web.php');
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
}

/**
Expand All @@ -82,7 +82,7 @@ private function registerRoutes()
private function publishConfiguration()
{
$this->publishes([
__DIR__ . '/../config/translation.php' => config_path('translation.php'),
__DIR__.'/../config/translation.php' => config_path('translation.php'),
], 'config');
}

Expand All @@ -93,7 +93,7 @@ private function publishConfiguration()
*/
private function mergeConfiguration()
{
$this->mergeConfigFrom(__DIR__ . '/../config/translation.php', 'translation');
$this->mergeConfigFrom(__DIR__.'/../config/translation.php', 'translation');
}

/**
Expand All @@ -104,7 +104,7 @@ private function mergeConfiguration()
private function publishAssets()
{
$this->publishes([
__DIR__ . '/../public/assets' => public_path('vendor/translation'),
__DIR__.'/../public/assets' => public_path('vendor/translation'),
], 'assets');
}

Expand All @@ -119,7 +119,7 @@ private function loadMigrations()
return;
}

$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
}

/**
Expand All @@ -129,10 +129,10 @@ private function loadMigrations()
*/
private function loadTranslations()
{
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'translation');
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'translation');

$this->publishes([
__DIR__ . '/../resources/lang' => resource_path('lang/vendor/translation'),
__DIR__.'/../resources/lang' => resource_path('lang/vendor/translation'),
]);
}

Expand Down Expand Up @@ -162,7 +162,7 @@ private function registerCommands()
*/
private function registerHelpers()
{
require __DIR__ . '/../resources/helpers.php';
require __DIR__.'/../resources/helpers.php';
}

/**
Expand Down
Loading