Skip to content

Commit

Permalink
Fix issue which failed to write changes to local language file when l…
Browse files Browse the repository at this point in the history
…ocale name contains '-'
  • Loading branch information
Vinson YUNG committed May 5, 2017
1 parent bcac640 commit 9e967d3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/Spreadsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Nikaia\TranslationSheet;

use Illuminate\Support\Str;
use Nikaia\TranslationSheet\Util;
use Nikaia\TranslationSheet\Client\Api;
use Nikaia\TranslationSheet\Sheet\Styles;
use Nikaia\TranslationSheet\Sheet\TranslationsSheetCoordinates;
Expand Down Expand Up @@ -83,6 +84,10 @@ public function getHeader()
public function getCamelizedHeader()
{
return array_map(function ($item) {
if (in_array($item, Util::asArray($this->getLocales()))) {
return $item;
}

return Str::camel($item);
}, $this->getHeader());
}
Expand Down
14 changes: 2 additions & 12 deletions src/TranslationSheetServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Nikaia\TranslationSheet;

use Illuminate\Support\ServiceProvider;
use Nikaia\TranslationSheet\Util;
use Nikaia\TranslationSheet\Client\Client;
use Nikaia\TranslationSheet\Commands\Lock;
use Nikaia\TranslationSheet\Commands\Open;
Expand Down Expand Up @@ -48,7 +49,7 @@ private function registerSpreadsheet()
$this->app->singleton(Spreadsheet::class, function () {
return new Spreadsheet(
$this->app['config']['translation_sheet.spreadsheetId'],
$this->asArray($this->app['config']['translation_sheet.locales'])
Util::asArray($this->app['config']['translation_sheet.locales'])
);
});
}
Expand All @@ -66,15 +67,4 @@ private function registerCommands()
Open::class,
]);
}

private function asArray($value)
{
if (is_array($value)) {
return $value;
}

return array_filter(array_map(function ($item) {
return trim($item);
}, explode(',', $value)));
}
}
11 changes: 11 additions & 0 deletions src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@ public static function keyValues($values, $keys)
return array_combine($keys, $values);
});
}

public static function asArray($value)
{
if (is_array($value)) {
return $value;
}

return array_filter(array_map(function ($item) {
return trim($item);
}, explode(',', $value)));
}
}

0 comments on commit 9e967d3

Please sign in to comment.