Skip to content

Commit

Permalink
Added translations to exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
todstoychev committed Nov 14, 2015
2 parents a603cf1 + 53909ff commit 4fe6076
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 19 deletions.
18 changes: 18 additions & 0 deletions resources/lang/bg/exceptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* BG translation for the exception messages
*/

return [
'uploads_path_missing' =>'Няма зададена стойнст за ключа "uploads_path" в текъщата конфигурация!',
'missing_context' => 'Няма зададени стойности за контекста :context',
'invalid_image_driver' => 'Невалидна или лисваща стойност за драйвера!',
'missing_parameter' => 'Параметърът :name не е зададен в конфигурацията!',
'invalid_config_value' => 'Невалидна стойност за :name !',
'extension_not_found' => 'Разширението на файла не е открито в пътеката!',
'mimetype_not_allowed' => 'Mime type не е разрешен!',
'file_extension_did_not_match' => 'Разширението на файла не съответства на типа му или е невалидно!',
'file_limit_exceeded' => 'Файлът е твърде голям!',
'image_too_small' => 'Снимката ви е твърде малка, опитайте с по-голяма!',

];
18 changes: 18 additions & 0 deletions resources/lang/en/exceptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* EN translations for the exceptions messages
*/

return [
'uploads_path_missing' =>'Array key "uploads_path" not set in configuration array!',
'missing_context' => 'No context values found for :context',
'invalid_image_driver' => 'Invalid or missing driver configuration value!',
'missing_parameter' => 'Parameter :name is not set in the configuration!',
'invalid_config_value' => 'Invalid configuration value provided for :name !',
'extension_not_found' => 'Extension not found in path!',
'mimetype_not_allowed' => 'Mime type not allowed!',
'file_extension_did_not_match' => 'File extension did not match the file mime type or it is not allowed!',
'file_limit_exceeded' => 'File too large',
'image_too_small' => 'Your image is too small. Try with larger image.',

];
4 changes: 2 additions & 2 deletions src/Handler/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function setConfig($config)
public function getUploadsPath()
{
if (!array_key_exists('uploads_path', $this->getConfig())) {
throw new Exception\NonExistingArrayKeyException('Array key "uploads_path" not set in configuration array!');
throw new Exception\NonExistingArrayKeyException(trans('icr::exceptions.uploads_path_missing'));
}

return $this->config['uploads_path'];
Expand All @@ -72,7 +72,7 @@ public function getUploadsPath()
public function getContextValues($context)
{
if (!array_key_exists($context, $this->config)) {
throw new Exception\NonExistingContextException("No context values found for '{$context}'");
throw new Exception\NonExistingContextException(trans('icr::exceptions.missing_context', ['context' => $context]));
}

return $this->config[$context];
Expand Down
14 changes: 6 additions & 8 deletions src/Handler/ConfigurationValidationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function validateContext($context)
{
// Check is context set
if (!array_key_exists($context, $this->getConfig())) {
throw new Exception\NonExistingContextException("Context {$context} does not exists!");
throw new Exception\NonExistingContextException(trans('icr::exceptions.missing_context', ['context' => $context]));
}

return $this;
Expand Down Expand Up @@ -65,7 +65,7 @@ public function validateDriver()
!array_key_exists('driver', $this->getConfig()) ||
!in_array($this->config['driver'], StaticData\Drivers::$allowedDrivers)
) {
throw new Exception\InvalidConfigurationValueException('Invalid or missing driver configuration value!');
throw new Exception\InvalidConfigurationValueException(trans('icr::exceptions.invalid_image_driver'));
}

return $this;
Expand All @@ -82,9 +82,7 @@ public function validateDriver()
protected function validateKeyValues($keyName, array $values)
{
if (!array_key_exists($keyName, $values)) {
throw new Exception\MandatoryConfigValueMissingException(
"Parameter {$keyName} is not set in the configuration!"
);
throw new Exception\MandatoryConfigValueMissingException(trans('icr::exceptions.missing_parameter', ['name' => $keyName]));
}
}

Expand All @@ -99,19 +97,19 @@ protected function validateValuesType(array $values)
{
if (!in_array($values['operation'], StaticData\Operations::$allowedOperations)) {
throw new Exception\InvalidConfigurationValueException(
'Invalid configuration value provided for operation!'
trans('icr::exceptions.invalid_config_value', ['name' => 'operation'])
);
}

if (!is_int($values['width'])) {
throw new Exception\InvalidConfigurationValueException(
'Invalid configuration value provided for width!'
trans('icr::exceptions.invalid_config_value', ['name' => 'width'])
);
}

if (!is_int($values['height'])) {
throw new Exception\InvalidConfigurationValueException(
'Invalid configuration value provided for height!'
trans('icr::exceptions.invalid_config_value', ['name' => 'height'])
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Handler/DeleteImageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public function deleteImageSizes($context, $fileName)
foreach ($this->getContextValues($context) as $key => $value) {
$image = $contextPath . '/' . $key . '/' . $fileName;

is_file($image) ? unlink($image) : null;
if (file_exists($image)) {
unlink($image);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Handler/OpenImageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function openWithGd($path)
$extension = array_shift($matches);

if (empty($extension)) {
throw new ExtensionNotFoundException('Extension not found in path!');
throw new ExtensionNotFoundException(trans('icr::exceptions.extension_not_found'));
}

$extension = str_replace('.', '', $extension);
Expand Down
8 changes: 3 additions & 5 deletions src/Handler/UploadedFileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,11 @@ protected function validateUploadedFile($context)
$extension = $this->getUploadedFile()->getClientOriginalExtension();

if (!array_key_exists($mimeType, $allowedFileTypes)) {
throw new Exception\NonAllowedMimeTypeException('Mime type not allowed!');
throw new Exception\NonAllowedMimeTypeException(trans('icr::exceptions.mimetype_not_allowed'));
}

if (!in_array($extension, $allowedFileTypes[$mimeType])) {
throw new Exception\NonAllowedFileExtensionException(
'File extension did not match the file mime type or it is not allowed!'
);
throw new Exception\NonAllowedFileExtensionException(trans('icr::exceptions.file_extension_did_not_match'));
}

return $this;
Expand All @@ -122,7 +120,7 @@ protected function checkFileSize()
$mb = str_replace('M', '', $phpIni);
$bytes = $mb * 1048576;
if ($this->getUploadedFile()->getSize() > $bytes) {
throw new Exception\FileLimitExceededException('File too large');
throw new Exception\FileLimitExceededException(trans('icr::exceptions.file_limit_exceeded'));
}
return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/ResizeCropOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function calculateRatio()
$ratio = min($widthRatio, $heightRatio);

if ($ratio < 1) {
throw new ResizeRatioException('Your image is too small. Try with larger image.');
throw new ResizeRatioException(trans('icr::exceptions.image_too_small'));
}

return $ratio;
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/ResizeOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function calculateRatio()
$ratio = min($widthRatio, $heightRatio);

if ($ratio < 1) {
throw new ResizeRatioException('Your image is too small. Try with larger image.');
throw new ResizeRatioException(trans('icr::exceptions.image_too_small'));
}

return $ratio;
Expand Down
2 changes: 2 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ class ServiceProvider extends BaseServiceProvider
public function boot()
{
$this->mergeConfigFrom(__DIR__ . '/config/config.php', 'icr');
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'icr');

$this->publishes([
__DIR__ . '/config/config.php' => config_path('icr/config.php'),
__DIR__ . '/../resources/lang' => base_path('resources/lang/todstoychev/icr')
]);
}

Expand Down

0 comments on commit 4fe6076

Please sign in to comment.