Top Level Namespace

Includes:
Turbo::FramesHelper, Turbo::Streams::Broadcasts, Turbo::Streams::StreamName

Defined Under Namespace

Modules: Devise, Forms, Icons, Input, Tables, Tag, Tybo Classes: AttachmentCardComponent, AttachmentsListComponent, BoGenerator, BoNamespaceGenerator, CoverComponent, CurrentUserMiniCardComponent, FormComponent, IndexComponent, IndexHeaderAddComponent, IndexHeaderComponent, IndexHeaderExportComponent, SidebarComponent, SidebarItemComponent, SignOutButtonComponent, TyboInstallGenerator

Instance Method Summary collapse

Instance Method Details

#create_base_translation_filesObject



3
4
5
6
7
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
43
44
# File 'lib/generators/tybo_install/utils/translations.rb', line 3

def create_base_translation_files
  %w[en fr].each do |locale|
    locale_file = "config/locales/bo.#{locale}.yml"
    File.write(locale_file, {
      locale => {
        'bo' => {
          'filters' => find_existing_translation('filters', locale),
          'show' => find_existing_translation('show', locale),
          'to' => find_existing_translation('to', locale),
          'export_btn' => find_existing_translation('export_btn', locale),
          'confirm_delete' => find_existing_translation('confirm_delete', locale),
          'record' => {
            'created' => find_existing_translation('created', locale),
            'updated' => find_existing_translation('updated', locale),
            'destroyed' => find_existing_translation('destroyed', locale),
        },
        'nav' => {
          'prev' => find_existing_translation('prev', locale),
          'next' => find_existing_translation('next', locale),
          'gap' => find_existing_translation('gap', locale)
        },
        'pagy' => {
          'showing' =>  find_existing_translation('showing', locale),
          'to' =>  find_existing_translation('to', locale),
          'of' =>  find_existing_translation('of', locale),
          'show' =>  find_existing_translation('show', locale),
          'results' =>  find_existing_translation('results', locale)
         },
        'devise' => {
          'password' => find_existing_translation('password', locale),
          'forgot_password' => find_existing_translation('forgot_password', locale),
          'reset_password_instructions' => find_existing_translation('reset_password_instructions', locale),
          'remember_me' => find_existing_translation('remember_me', locale),
          'sign_in' => find_existing_translation('sign_in', locale),
          'send_me_reset_password_instructions' => find_existing_translation('send_me_reset_password_instructions', locale),
          'save' => find_existing_translation('save', locale),
          }
        }
      }
    }.to_yaml)
  end
end

#create_translationsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/generators/bo/utils/translations.rb', line 3

def create_translations
  %w[en fr].each do |locale|
    locale_file = "config/locales/bo.#{locale}.yml"
    yaml_string = File.open locale_file
    data = YAML.load yaml_string
    data[locale]['bo'][file_name.underscore] = {
      'one' => find_existing_translation(bo_model.to_s.downcase, locale),
      'others' => find_existing_translation(bo_model.to_s.pluralize.downcase, locale),
      'new' => find_existing_translation(nil, locale),
      'subtitle' => find_existing_translation("list of #{bo_model.to_s.pluralize.downcase}", locale),
      'attributes' => model_attributes(data, locale)
    }
    output = YAML.dump data
    File.write(locale_file, output)
  end
end

#find_existing_translation(col, locale) ⇒ Object



28
29
30
31
32
33
# File 'lib/generators/bo/utils/translations.rb', line 28

def find_existing_translation(col, locale)
  return col.to_s.humanize.capitalize if locale == 'en'

  json = JSON.parse(File.read("#{__dir__}/files/#{locale}.json"))
  json[col.to_s]
end

#model_attributes(data, locale) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/generators/bo/utils/translations.rb', line 20

def model_attributes(data, locale)
  hash = data.dig(locale, 'bo', file_name.underscore, 'attributes') || {}
  model_columns.each do |col|
    hash[col.to_s] ||= find_existing_translation(col, locale)
  end
  hash
end