diff --git a/classes/ComponentHelper.php b/classes/ComponentHelper.php index 7582e6e..a59216c 100644 --- a/classes/ComponentHelper.php +++ b/classes/ComponentHelper.php @@ -5,6 +5,7 @@ use Exception; use Winter\Storm\Support\Traits\Singleton; use ApplicationException; +use Lang; /** * Provides helper methods for Builder CMS components. @@ -64,7 +65,7 @@ public function getModelClassDesignTime() $modelClass = trim(Input::get('modelClass')); if ($modelClass && !is_scalar($modelClass)) { - throw new ApplicationException('Model class name should be a string.'); + throw new ApplicationException(Lang::get('winter.builder::lang.components.error_model_class_name_should_be_a_string')); } if (!strlen($modelClass)) { @@ -73,7 +74,7 @@ public function getModelClassDesignTime() } if (!ModelModel::validateModelClassName($modelClass)) { - throw new ApplicationException('Invalid model class name.'); + throw new ApplicationException(Lang::get('winter.builder::lang.components.error_invalid_model_class_name')); } return $modelClass; diff --git a/classes/IndexOperationsBehaviorBase.php b/classes/IndexOperationsBehaviorBase.php index cfa0c85..f395f4d 100644 --- a/classes/IndexOperationsBehaviorBase.php +++ b/classes/IndexOperationsBehaviorBase.php @@ -3,6 +3,7 @@ use Backend\Classes\ControllerBehavior; use Backend\Behaviors\FormController; use ApplicationException; +use Lang; /** * Base class for index operation behaviors @@ -17,7 +18,7 @@ abstract class IndexOperationsBehaviorBase extends ControllerBehavior protected function makeBaseFormWidget($modelCode, $options = [], $aliasSuffix = null) { if (!strlen($this->baseFormConfigFile)) { - throw new ApplicationException(sprintf('Base form configuration file is not specified for %s behavior', get_class($this))); + throw new ApplicationException(Lang::get('winter.builder::lang.behavior.error_base_form_configuration_file_is_not_specified', ['class' => get_class($this)])); } $widgetConfig = $this->makeConfig($this->baseFormConfigFile); @@ -36,7 +37,7 @@ protected function getPluginCode() $vector = $this->controller->getBuilderActivePluginVector(); if (!$vector) { - throw new ApplicationException('Cannot determine the currently active plugin.'); + throw new ApplicationException(Lang::get('winter.builder::lang.behavior.error_cannot_determine_currently_active_plugin')); } return $vector->pluginCodeObj; diff --git a/classes/LanguageMixer.php b/classes/LanguageMixer.php index aa871c0..6abd597 100644 --- a/classes/LanguageMixer.php +++ b/classes/LanguageMixer.php @@ -3,6 +3,7 @@ use Yaml; use Symfony\Component\Yaml\Dumper as YamlDumper; use ApplicationException; +use Lang; class LanguageMixer { @@ -28,7 +29,7 @@ public function addStringsFromAnotherLanguage($destContents, $srcArray) $destArray = Yaml::parse($destContents); } catch (Exception $ex) { - throw new ApplicationException(sprintf('Cannot parse the YAML content: %s', $ex->getMessage())); + throw new ApplicationException(Lang::get('winter.builder::lang.localization.error_cannot_parse_yaml', ['message' => $ex->getMessage()])); } if (!$destArray) { diff --git a/classes/LocalizationModel.php b/classes/LocalizationModel.php index a0720d3..042e2d4 100644 --- a/classes/LocalizationModel.php +++ b/classes/LocalizationModel.php @@ -118,7 +118,7 @@ public function save() public function deleteModel() { if ($this->isNewModel()) { - throw new ApplicationException('Cannot delete language file which is not saved yet.'); + throw new ApplicationException(Lang::get('winter.builder::lang.localization.error_cannot_delete_lang_file_which_is_not_saved')); } $filePath = File::symbolizePath($this->getFilePath()); @@ -227,7 +227,7 @@ public static function getDefaultLanguage() $language = Config::get('app.locale'); if (!$language) { - throw new ApplicationException('The default language is not defined in the application configuration (app.locale).'); + throw new ApplicationException(Lang::get('winter.builder::lang.localization.error_default_language_is_not_defined')); } return $language; @@ -333,7 +333,7 @@ protected function getFilePath($language = null) } if (!$this->validateLanguage($language)) { - throw new SystemException('Invalid language file name: '.$language); + throw new SystemException('Invalid language file name: ' . $language); } $path = $this->getPluginCodeObj()->toPluginDirectoryPath().'/lang/'.$language.'/lang.php'; @@ -364,7 +364,7 @@ protected function modelToLanguageFile() return "getMessage())); + throw new ApplicationException(Lang::get('winter.builder::lang.localization.error_cannot_parse_yaml'), ['message' => $ex->getMessage()]); } } diff --git a/classes/MenusModel.php b/classes/MenusModel.php index 9c5c4de..042d031 100644 --- a/classes/MenusModel.php +++ b/classes/MenusModel.php @@ -35,7 +35,7 @@ protected function modelToYamlArray() $mainMenuItem = $this->trimMenuProperties($mainMenuItem); if (!isset($mainMenuItem['code'])) { - throw new ApplicationException('Cannot save menus - the main menu item code should not be empty.'); + throw new ApplicationException(Lang::get('winter.builder::lang.menu.error_main_menu_item_code_should_not_be_empty')); } if (isset($mainMenuItem['sideMenu'])) { @@ -45,7 +45,7 @@ protected function modelToYamlArray() $sideMenuItem = $this->trimMenuProperties($sideMenuItem); if (!isset($sideMenuItem['code'])) { - throw new ApplicationException('Cannot save menus - the side menu item code should not be empty.'); + throw new ApplicationException(Lang::get('winter.builder::lang.menu.error_side_menu_item_code_should_not_be_empty')); } $code = $sideMenuItem['code']; diff --git a/classes/MigrationModel.php b/classes/MigrationModel.php index 2a87a0d..4ab5d35 100644 --- a/classes/MigrationModel.php +++ b/classes/MigrationModel.php @@ -151,12 +151,12 @@ public function load($versionNumber) $versionNumber = trim($versionNumber); if (!strlen($versionNumber)) { - throw new ApplicationException('Cannot load the the version model - the version number should not be empty.'); + throw new ApplicationException(Lang::get('winter.builder::lang.migration.error_cannot_load_version_model_should_not_be_empty')); } $pluginVersions = $this->getPluginVersionInformation(); if (!array_key_exists($versionNumber, $pluginVersions)) { - throw new ApplicationException('The requested version does not exist in the version information file.'); + throw new ApplicationException(Lang::get('winter.builder::lang.migration.error_requested_version_does_not_exist')); } $this->version = $versionNumber; @@ -171,7 +171,7 @@ public function load($versionNumber) $cnt = count($versionInformation); if ($cnt > 2) { - throw new ApplicationException('The requested version cannot be edited with Builder as it refers to multiple PHP scripts.'); + throw new ApplicationException(Lang::get('winter.builder::lang.migration.error_requested_version_cannot_be_edited')); } if ($cnt > 0) { @@ -373,7 +373,7 @@ protected function loadScriptFile() $scriptFilePath = $this->getPluginUpdatesPath($this->scriptFileName.'.php'); if (!File::isFile($scriptFilePath)) { - throw new ApplicationException(sprintf('Version file %s is not found.', $scriptFilePath)); + throw new ApplicationException(Lang::get('winter.builder::lang.migration.error_version_file_is_not_found', ['path' => $scriptFilePath])); } return File::get($scriptFilePath); diff --git a/classes/ModelFormModel.php b/classes/ModelFormModel.php index 2a90dd9..8c80253 100644 --- a/classes/ModelFormModel.php +++ b/classes/ModelFormModel.php @@ -2,6 +2,7 @@ use SystemException; use ValidationException; +use Lang; /** * Represents and manages model forms. @@ -131,7 +132,7 @@ public function validate() parent::validate(); if (!$this->controls) { - throw new ValidationException(['controls' => 'Please create at least one field.']); + throw new ValidationException(['controls' => Lang::get('winter.builder::lang.form.validation_create_at_least_one_field')]); } } diff --git a/classes/ModelListModel.php b/classes/ModelListModel.php index 035fc43..89f86d1 100644 --- a/classes/ModelListModel.php +++ b/classes/ModelListModel.php @@ -37,7 +37,7 @@ public function fill(array $attributes) $attributes['columns'] = json_decode($attributes['columns'], true); if ($attributes['columns'] === null) { - throw new SystemException('Cannot decode columns JSON string.'); + throw new SystemException('Cannot decode columns JSON string.')); } } @@ -66,7 +66,7 @@ public function validate() $this->validateDupicateColumns(); if (!$this->columns) { - throw new ValidationException(['columns' => 'Please create at least one column.']); + throw new ValidationException(['columns' => Lang::get('winter.builder::lang.list.validation_columns_create_at_least_one_column')]); } } @@ -101,7 +101,7 @@ protected function modelToYamlArray() foreach ($this->columns as $column) { if (!isset($column['field'])) { - throw new ApplicationException('Cannot save the list - the column field name should not be empty.'); + throw new ApplicationException(Lang::get('winter.builder::lang.list.error_name_should_not_be_empty')); } $columnName = $column['field']; diff --git a/classes/ModelModel.php b/classes/ModelModel.php index 7f93afa..c6ef4ec 100644 --- a/classes/ModelModel.php +++ b/classes/ModelModel.php @@ -306,7 +306,7 @@ public static function getModelColumnsAndTypes($pluginCodeObj, $modelClassName) $tableName = self::getTableNameFromModelClass($pluginCodeObj, $modelClassName); if (!DatabaseTableModel::tableExists($tableName)) { - throw new ApplicationException('Database table not found: '.$tableName); + throw new ApplicationException(Lang::get('winter.builder::lang.model.error_db_table_not_found', ['table' => $tableName])); } $schema = DatabaseTableModel::getSchema(); diff --git a/classes/PermissionsModel.php b/classes/PermissionsModel.php index 90e66e2..0e48f94 100644 --- a/classes/PermissionsModel.php +++ b/classes/PermissionsModel.php @@ -48,7 +48,7 @@ protected function modelToYamlArray() } if (!isset($permission['permission'])) { - throw new ApplicationException('Cannot save permissions - the permission code should not be empty.'); + throw new ApplicationException(Lang::get('winter.builder::lang.permission.error_save_permissions_code_should_not_be_empty')); } $code = $permission['permission']; diff --git a/classes/PluginCode.php b/classes/PluginCode.php index 7fba203..82ebca5 100644 --- a/classes/PluginCode.php +++ b/classes/PluginCode.php @@ -1,6 +1,7 @@ $pluginCodeStr])); } list($authorCode, $pluginCode) = $codeParts; if (!$this->validateCodeWord($authorCode) || !$this->validateCodeWord($pluginCode)) { - throw new ApplicationException(sprintf('Invalid plugin code: %s', $pluginCodeStr)); + throw new ApplicationException(Lang::get('winter.builder::lang.plugin.error_invalid_plugin_code', ['code' => $pluginCodeStr])); } $this->authorCode = trim($authorCode); @@ -35,7 +36,7 @@ public static function createFromNamespace($namespace) { $namespaceParts = explode('\\', $namespace); if (count($namespaceParts) < 2) { - throw new ApplicationException('Invalid plugin namespace value.'); + throw new ApplicationException(Lang::get('winter.builder::lang.plugin.error_invalid_plugin_namespace')); } $authorCode = $namespaceParts[0]; diff --git a/classes/YamlModel.php b/classes/YamlModel.php index 79d9023..d9992df 100644 --- a/classes/YamlModel.php +++ b/classes/YamlModel.php @@ -102,14 +102,14 @@ protected function load($filePath) $filePath = File::symbolizePath($filePath); if (!File::isFile($filePath)) { - throw new ApplicationException('Cannot load the model - the original file is not found: '.basename($filePath)); + throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_load_model_file_is_not_found', ['path' => basename($filePath)])); } try { $data = Yaml::parse(File::get($filePath)); } catch (Exception $ex) { - throw new ApplicationException(sprintf('Cannot parse the YAML file %s: %s', basename($filePath), $ex->getMessage())); + throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_parse_yaml_file', ['path' => basename($filePath), 'message' => $ex->getMessage()])); } $this->originalFilePath = $filePath; @@ -134,11 +134,11 @@ protected function load($filePath) public function deleteModel() { if (!File::isFile($this->originalFilePath)) { - throw new ApplicationException('Cannot load the model - the original file is not found: '.$filePath); + throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_load_model_file_is_not_found', ['path' => $filePath])); } if (strtolower(substr($this->originalFilePath, -5)) !== '.yaml') { - throw new ApplicationException('Cannot delete the model - the original file should be a YAML document'); + throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_delete_model_file_should_be_yaml')); } File::delete($this->originalFilePath); diff --git a/lang/en/lang.php b/lang/en/lang.php index 239792f..59dc6be 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -33,6 +33,8 @@ 'replaces_prompt' => 'Add a plugin', 'replaces_plugin_code' => 'Plugin code', 'replaces_plugin_constraint' => 'Version constraint', + 'error_invalid_plugin_code' => 'Invalid plugin code: :code', + 'error_invalid_plugin_namespace' => 'Invalid plugin namespace value.', ], 'author_name' => [ 'title' => 'Author name', @@ -110,6 +112,7 @@ 'error_deleted_at_column_must_exist' => 'The database table must have deleted_at column.', 'add_form' => 'Add form', 'add_list' => 'Add list', + 'error_db_table_not_found' => 'Database table not found: :table', 'delete_model' => 'Delete model :model', 'delete_model_confirm' => 'Are you sure you wish to delete the ":model" model? This will also remove any forms and lists connected to the model.', 'deleted' => 'Model ":model" successfully deleted.', @@ -399,6 +402,7 @@ 'tab_css_class_description' => 'Assigns a CSS class to the tabs container.', 'tab_name_template' => 'Tab %s', 'tab_already_exists' => 'Tab with the specified title already exists.', + 'validation_create_at_least_one_field' => 'Please create at least one field.', ], 'list' => [ 'tab_new_list' => 'New list', @@ -437,7 +441,9 @@ 'column_label_value_from' => 'Value from', 'error_duplicate_column' => "Duplicate column field name: ':column'.", 'btn_add_database_columns' => 'Add database columns', - 'all_database_columns_exist' => 'All database columns are already defined in the list' + 'all_database_columns_exist' => 'All database columns are already defined in the list', + 'validation_columns_create_at_least_one_column' => 'Please create at least one column.', + 'error_name_should_not_be_empty' => 'Cannot save the list - the column field name should not be empty.', ], 'controller' => [ 'menu_label' => 'Controllers', @@ -611,6 +617,8 @@ 'property_code_required' => 'Please enter the menu item code.', 'error_duplicate_main_menu_code' => "Duplicate main menu item code: ':code'.", 'error_duplicate_side_menu_code' => "Duplicate side menu item code: ':code'.", + 'error_main_menu_item_code_should_not_be_empty' => 'Cannot save menus - the main menu item code should not be empty.', + 'error_side_menu_item_code_should_not_be_empty' => 'Cannot save menus - the side menu item code should not be empty.', ], 'localization' => [ 'menu_label' => 'Localization', @@ -639,6 +647,9 @@ 'string_key_is_a_string' => ':key is a string and cannot contain other strings.', 'string_value_is_empty' => 'String value should not be empty', 'string_key_exists' => 'The string key already exists', + 'error_cannot_delete_lang_file_which_is_not_saved' => 'Cannot delete language file which is not saved yet.', + 'error_default_language_is_not_defined' => 'The default language is not defined in the application configuration (app.locale).', + 'error_cannot_parse_yaml' => 'Cannot parse the YAML content: :message', ], 'permission' => [ 'menu_label' => 'Permissions', @@ -654,9 +665,14 @@ 'column_label_required' => 'Please enter the permission label', 'saved' => 'Permissions saved', 'error_duplicate_code' => "Duplicate permission code: ':code'.", + 'error_save_permissions_code_should_not_be_empty' => 'Cannot save permissions - the permission code should not be empty.', ], 'yaml' => [ 'save_error' => "Error saving file ':name'. Please check write permissions.", + 'error_cannot_load_model_file_is_not_found' => 'Cannot load the model - the original file is not found: :path', + 'error_cannot_parse_yaml_file' => 'Cannot parse the YAML file :path: :message', + 'error_cannot_load_model_file_is_not_found' => 'Cannot load the model - the original file is not found: :path', + 'error_cannot_delete_model_file_should_be_yaml' => 'Cannot delete the model - the original file should be a YAML document', ], 'common' => [ 'error_file_exists' => "File already exists: ':path'.", @@ -687,6 +703,10 @@ 'error_namespace_mismatch' => "The migration code should use the plugin namespace: :namespace", 'error_migration_file_exists' => "Migration file :file already exists. Please use another class name.", 'error_cant_delete_applied' => 'This version has already been applied and cannot be deleted. Please rollback the version first.', + 'error_cannot_load_version_model_should_not_be_empty' => 'Cannot load the version model - the version number should not be empty.', + 'error_requested_version_does_not_exist' => 'The requested version does not exist in the version information file.', + 'error_requested_version_cannot_be_edited' => 'The requested version cannot be edited with Builder as it refers to multiple PHP scripts.', + 'error_version_file_is_not_found' => 'Version file :path is not found', ], 'components' => [ 'list_title' => 'Record list', @@ -738,12 +758,18 @@ 'details_not_found_message' => 'Not found message', 'details_not_found_message_description' => 'Message to display if the record is not found. Used in the default component\'s partial.', 'details_not_found_message_default' => 'Record not found', + 'error_invalid_model_class_name' => 'Invalid model class name.', + 'error_model_class_name_should_be_a_string' => 'Model class name should be a string.', ], 'validation' => [ - 'reserved' => ':attribute cannot be a PHP reserved keyword' + 'reserved' => ':attribute cannot be a PHP reserved keyword', + ], + 'behavior' => [ + 'error_base_form_configuration_file_is_not_specified' => 'Base form configuration file is not specified for :class behavior', + 'error_cannot_determine_currently_active_plugin' => 'Cannot determine the currently active plugin.', ], 'settings' => [ - 'menu_desc' => 'Set your author name and namespace for plugin creation.' + 'menu_desc' => 'Set your author name and namespace for plugin creation.', ], 'welcome' => [ 'heading' => 'Welcome to the Builder.',