Skip to content

Commit

Permalink
Fix yml-based translations to match format of wiki-based translations
Browse files Browse the repository at this point in the history
For the wiki-based translations, we use symbols as keys for individual fields of translated content. This makes ensures the yml-based module and slide translations have the same key format, so that they will actually render.
  • Loading branch information
ragesoss committed Jan 31, 2025
1 parent 5ed2364 commit 40f4473
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/training_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def inflate_content_hash(content)
self.name = content['name'] || content[:name]
self.description = content['description'] || content[:description]
self.estimated_ttc = content['estimated_ttc']
self.translations = content['translations']
self.translations = TrainingBase.format_translation_keys content['translations']
self.settings = content['settings']
self.slide_slugs = content['slides'].pluck('slug')
end
Expand Down
11 changes: 11 additions & 0 deletions lib/training/training_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ def self.training_loader_class
Features.wiki_trainings? ? WikiTrainingLoader : YamlTrainingLoader
end

# Takes a hash of translations and turns the keys within each
# locale into symbols, so that yml-based translations will have
# the same format as wiki-based translations.
def self.format_translation_keys(translations_hash)
return unless translations_hash
translations_hash.each_key do |locale_key|
translations_hash[locale_key] = translations_hash[locale_key].transform_keys(&:to_sym)
end
translations_hash
end

class DuplicateSlugError < StandardError
end
end

0 comments on commit 40f4473

Please sign in to comment.