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, TyboUpgradeGenerator
Constant Summary collapse
- FR_DATE_TRANSLATIONS =
{ 'date' => { 'abbr_day_names' => %w[Dim Lun Mar Mer Jeu Ven Sam], 'day_names' => %w[Dimanche Lundi Mardi Mercredi Jeudi Vendredi Samedi], 'abbr_month_names' => [nil, 'Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Juin', 'Juil', 'Aoû', 'Sep', 'Oct', 'Nov', 'Déc'], 'month_names' => [nil, 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'], 'formats' => { 'default' => '%d/%m/%Y', 'short' => '%e %b', 'long' => '%e %B %Y' } }, 'time' => { 'am' => 'am', 'pm' => 'pm', 'formats' => { 'default' => '%A %d %B %Y %H:%M:%S %z', 'short' => '%d %b %H:%M', 'long' => '%A %d %B %Y %H:%M' } }, 'datetime' => { 'distance_in_words' => { 'half_a_minute' => 'une demi-minute', 'less_than_x_seconds' => { 'one' => "moins d'une seconde", 'other' => 'moins de %{count} secondes' }, 'x_seconds' => { 'one' => '1 seconde', 'other' => '%{count} secondes' }, 'less_than_x_minutes' => { 'one' => "moins d'une minute", 'other' => 'moins de %{count} minutes' }, 'x_minutes' => { 'one' => '1 minute', 'other' => '%{count} minutes' }, 'about_x_hours' => { 'one' => 'environ 1 heure', 'other' => 'environ %{count} heures' }, 'x_days' => { 'one' => '1 jour', 'other' => '%{count} jours' }, 'about_x_months' => { 'one' => 'environ 1 mois', 'other' => 'environ %{count} mois' }, 'x_months' => { 'one' => '1 mois', 'other' => '%{count} mois' }, 'about_x_years' => { 'one' => 'environ 1 an', 'other' => 'environ %{count} ans' }, 'over_x_years' => { 'one' => "plus d'un an", 'other' => 'plus de %{count} ans' }, 'almost_x_years' => { 'one' => 'presque 1 an', 'other' => 'presque %{count} ans' } } } }.freeze
Instance Method Summary collapse
- #create_base_translation_files ⇒ Object
- #create_translations ⇒ Object
- #find_existing_translation(col, locale) ⇒ Object
- #model_attributes(data, locale) ⇒ Object
Instance Method Details
#create_base_translation_files ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/generators/tybo_install/utils/translations.rb', line 34 def create_base_translation_files %w[en fr].each do |locale| locale_file = "config/locales/bo.#{locale}.yml" extra = locale == 'fr' ? FR_DATE_TRANSLATIONS : {} File.write(locale_file, { locale => extra.merge({ '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), 'add_ressource_btn' => find_existing_translation('add_ressource_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_translations ⇒ Object
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 |