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

Temp fix for translations in vendor folders #433

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "barryvdh/laravel-translation-manager",
"name": "tankonyako/laravel-translation-manager",
"description": "Manage Laravel Translations",
"keywords": [
"laravel",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This way, translations can be saved in git history and no overhead is introduced

Require this package in your composer.json and run composer update (or run `composer require barryvdh/laravel-translation-manager` directly):

composer require barryvdh/laravel-translation-manager
composer require tankonyako/laravel-translation-manager


You need to run the migrations for this package.
Expand Down
35 changes: 19 additions & 16 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function importTranslations($replace = false, $base = null, $import_group
$translations = \Lang::getLoader()->load($locale, $group);
} else {
$translations = include $file;
$group = 'vendor/'.$vendorName;
$group = 'vendor/'.$vendorName.'/'.$group;
}

if ($translations && is_array($translations)) {
Expand Down Expand Up @@ -252,19 +252,26 @@ public function missingKey($namespace, $group, $key)

public function exportTranslations($group = null, $json = false)
{
$group = basename($group);
$vendor = false;

$baseGroup = basename($group);
if ($group == '*') {
return $this->exportAllTranslations();
} else {
if (Str::startsWith($group, 'vendor'))
{
$vendor = true;
}
else
{
$group = basename($group);
}
}

$basePath = $this->app['path.lang'];

if (! is_null($group) && ! $json) {
if (! in_array($group, $this->config['exclude_groups'])) {
$vendor = false;
if ($group == '*') {
return $this->exportAllTranslations();
} else {
if (Str::startsWith($group, 'vendor')) {
$vendor = true;
}
}

$tree = $this->makeTree(Translation::ofTranslatedGroup($group)
->orderByGroupKeys(Arr::get($this->config, 'sort_keys', false))
Expand All @@ -278,7 +285,7 @@ public function exportTranslations($group = null, $json = false)

$locale_path = $locale.DIRECTORY_SEPARATOR.$group;
if ($vendor) {
$path = $basePath.'/'.$group.'/'.$locale;
$path = $basePath.'/'.dirname($group);
$locale_path = Str::after($group, '/');
}
$subfolders = explode(DIRECTORY_SEPARATOR, $locale_path);
Expand All @@ -294,11 +301,7 @@ public function exportTranslations($group = null, $json = false)
}
}

if ($vendor) {
$path = $path.DIRECTORY_SEPARATOR.'messages.php';
} else {
$path = $path.DIRECTORY_SEPARATOR.$locale.DIRECTORY_SEPARATOR.$group.'.php';
}
$path = $path.DIRECTORY_SEPARATOR.$locale.DIRECTORY_SEPARATOR.$baseGroup.'.php';

$output = "<?php\n\nreturn ".var_export($translations, true).';'.\PHP_EOL;
$this->files->put($path, $output);
Expand Down