Class: I18nYaml::Generators::ScaffoldControllerGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- I18nYaml::Generators::ScaffoldControllerGenerator
- Includes:
- I18nYamlGenerator::Helpers, Rails::Generators::ResourceHelpers
- Defined in:
- lib/generators/i18n_yaml/scaffold_controller/scaffold_controller_generator.rb
Overview
:nodoc:
Instance Method Summary collapse
Methods included from I18nYamlGenerator::Helpers
#comment_yaml_body, #wrap_hash
Instance Method Details
#views_i18n_yaml_file ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/generators/i18n_yaml/scaffold_controller/scaffold_controller_generator.rb', line 8 def views_i18n_yaml_file titles_hash = { 'index' => { 'title' => "#{human_name.pluralize}" }, 'show' => { 'title' => human_name }, 'edit' => { 'title' => "Editing #{human_name}" }, 'new' => { 'title' => "New #{human_name}" } } flash_hash = { 'create' => { 'notice' => '%{resource_name} was successfully created.' }, 'update' => { 'notice' => '%{resource_name} was successfully updated.' }, 'destroy' => { 'notice' => '%{resource_name} was successfully deleted.', 'alert' => '%{resource_name} could not be deleted.' } } scope_array = controller_i18n_scope.split('.') I18n.available_locales.each do |locale| hash_for_yaml = {} hash_for_yaml.deep_merge! wrap_hash(titles_hash, scope_array) hash_for_yaml.deep_merge! wrap_hash(flash_hash, %w(flash) + scope_array) yaml_content = { locale.to_s => hash_for_yaml }.to_yaml destination_path = File.join('config/locales/views/', "#{controller_file_path}.#{locale}.yml") create_file destination_path, .commented ? comment_yaml_body(yaml_content) : yaml_content end end |