def import_translations(path, page)
      old_translations = page.translations.pluck(:locale)
      new_translations = []

      Dir["#{path}content.*.html"].each do |file_path|
        locale = File.basename(file_path).match(%r{content\.(\w+)\.html})[1]
        new_translations << locale

        translation = page.translations.where(locale: locale).first_or_initialize

        next unless fresh_seed?(translation, file_path)

        # reading file content in, resulting in a hash
        fragments_hash  = parse_file_content(file_path)

        # parsing attributes section
        attributes_yaml = fragments_hash.delete("attributes")
        attrs           = YAML.safe_load(attributes_yaml)

        # applying attributes
        layout = site.layouts.find_by(identifier: attrs.delete("layout")) || page.try(:layout)
        translation.attributes = attrs.merge(
          layout: layout
        )

        # applying fragments
        old_frag_identifiers = translation.fragments.pluck(:identifier)

        new_frag_identifiers, fragments_attributes =
          construct_fragments_attributes(fragments_hash, translation, path)
        translation.fragments_attributes = fragments_attributes

        if translation.save
          message = "[CMS SEEDS] Imported Translation \t #{locale}"
          ComfortableMexicanSofa.logger.info(message)

          # cleaning up old fragments
          frags_to_remove = old_frag_identifiers - new_frag_identifiers
          translation.fragments.where(identifier: frags_to_remove).destroy_all

        else
          message = "[CMS SEEDS] Failed to import Translation \n#{locale}"
          ComfortableMexicanSofa.logger.warn(message)
        end
      end

      # Cleaning up removed translations
      translations_to_remove = old_translations - new_translations
      page.translations.where(locale: translations_to_remove).destroy_all
    end
def import_translations(path, page)
      old_translations = page.translations.pluck(:locale)
      new_translations = []

      Dir["#{path}content.*.html"].each do |file_path|
        locale = File.basename(file_path).match(%r{content\.(\w+)\.html})[1]
        new_translations << locale

        translation = page.translations.where(locale: locale).first_or_initialize

        next unless fresh_seed?(translation, file_path)

        # reading file content in, resulting in a hash
        fragments_hash  = parse_file_content(file_path)

        # parsing attributes section
        attributes_yaml = fragments_hash.delete("attributes")
        attrs           = YAML.safe_load(attributes_yaml)

        # applying attributes
        layout = site.layouts.find_by(identifier: attrs.delete("layout")) || page.try(:layout)
        translation.attributes = attrs.merge(
          layout: layout
        )

        # applying fragments
        old_frag_identifiers = translation.fragments.pluck(:identifier)

        new_frag_identifiers, fragments_attributes =
          construct_fragments_attributes(fragments_hash, translation, path)
        translation.fragments_attributes = fragments_attributes

        if translation.save
          message = "[CMS SEEDS] Imported Translation \t #{locale}"
          ComfortableMexicanSofa.logger.info(message)

          # cleaning up old fragments
          frags_to_remove = old_frag_identifiers - new_frag_identifiers
          translation.fragments.where(identifier: frags_to_remove).destroy_all

        else
          message = "[CMS SEEDS] Failed to import Translation \n#{locale}"
          ComfortableMexicanSofa.logger.warn(message)
        end
      end

      # Cleaning up removed translations
      translations_to_remove = old_translations - new_translations
      page.translations.where(locale: translations_to_remove).destroy_all
    end
Importing translations for given page. They look like `content.locale.html`