# frozen_string_literal: true

#
# Copyright (C) 2021 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

module I18nTasks
  module CsvBackend
    def load_csv(filename)
      scope = File.basename(filename, ".*")
      data = CSV.read(filename, headers: true)
      csv_locales = data.headers - ["key"]
      ret = {}
      csv_locales.each do |locale|
        ret[locale.to_sym] = {
          scope.to_sym => data.map { |row| [row["key"].to_sym, row[locale]] }.to_h
        }
      end
      ret
    end
  end
end

# frozen_string_literal: true

#
# Copyright (C) 2021 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

module I18nTasks
  module CsvBackend
    def load_csv(filename)
      scope = File.basename(filename, ".*")
      data = CSV.read(filename, headers: true)
      csv_locales = data.headers - ["key"]
      ret = {}
      csv_locales.each do |locale|
        ret[locale.to_sym] = {
          scope.to_sym => data.map { |row| [row["key"].to_sym, row[locale]] }.to_h.compact
        }
      end
      ret
    end
  end
end

Drop explicitly empty community translations
Drop explicitly empty community translations

fixes FOO-2999

Change-Id: Idd0362bb41f27a68951a7b5cc77a1719d9c8d6ed
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/300655
Reviewed-by: August Thornton <9adc7a1161ddf32ff608de792a7e50179545f026@instructure.com>
Reviewed-by: Charley Kline <05950d7e90ba5e3da323378368c22b3ffaaf6647@instructure.com>
Tested-by: Service Cloud Jenkins <9144042a601061f88f1e1d7a1753ea3e2972119d@instructure.com>
QA-Review: Jacob Burroughs <8ecea6e385af5cf9f53123f5ca17fb5fd6a6d4b2@instructure.com>
Product-Review: Jacob Burroughs <8ecea6e385af5cf9f53123f5ca17fb5fd6a6d4b2@instructure.com>
