diff --git a/app/controllers/v3/tafsirs_controller.rb b/app/controllers/v3/tafsirs_controller.rb index d1ac3765..80f04422 100644 --- a/app/controllers/v3/tafsirs_controller.rb +++ b/app/controllers/v3/tafsirs_controller.rb @@ -1,6 +1,7 @@ class V3::TafsirsController < ApplicationController before_action :set_verse + # GET /chapter_id/verses/verse_number/tafsirs def index tafsirs = @verse.tafsirs @@ -18,14 +19,14 @@ def chapter end def set_verse - @verse = chapter.verses.find_by_id_or_key(params[:verse_id]) + @verse = chapter.verses.find_by_verse_number(params[:verse_id]) end def tafirs_filter return nil unless params[:tafsirs].present? ResourceContent.where(id: params[:tafsirs]) - .or(ResourceContent.where(slug: tafsirs)) + .or(ResourceContent.where(slug: params[:tafsirs])) .pluck(:id) end end diff --git a/app/models/resource_content.rb b/app/models/resource_content.rb index 6e2528fe..b5bd2ea6 100644 --- a/app/models/resource_content.rb +++ b/app/models/resource_content.rb @@ -16,6 +16,7 @@ # language_name :string # created_at :datetime not null # updated_at :datetime not null +# slug :string # class ResourceContent < ApplicationRecord diff --git a/app/models/tafsir.rb b/app/models/tafsir.rb index d85ec1be..1ca078c8 100644 --- a/app/models/tafsir.rb +++ b/app/models/tafsir.rb @@ -11,6 +11,7 @@ # created_at :datetime not null # updated_at :datetime not null # resource_name :string +# verse_key :string # class Tafsir < ApplicationRecord diff --git a/app/models/verse.rb b/app/models/verse.rb index a87f69bb..9155ad7e 100644 --- a/app/models/verse.rb +++ b/app/models/verse.rb @@ -46,6 +46,6 @@ class Verse < ApplicationRecord default_scope { order 'verse_number asc' } def self.find_by_id_or_key(id) - where(id: id).or(verse_key: id).first + where(id: id).or(where(verse_key: id)).first end end diff --git a/app/models/word.rb b/app/models/word.rb index 78709d61..48b9bc99 100644 --- a/app/models/word.rb +++ b/app/models/word.rb @@ -2,31 +2,32 @@ # # Table name: words # -# id :integer not null, primary key -# verse_id :integer -# chapter_id :integer -# position :integer -# text_madani :text -# text_indopak :text -# text_simple :text -# verse_key :string -# page_number :integer -# class_name :string -# line_number :integer -# code_dec :integer -# code_hex :string -# code_hex_v3 :string -# code_dec_v3 :integer -# char_type_id :integer -# created_at :datetime not null -# updated_at :datetime not null -# pause_name :string -# audio_url :string -# image_blob :text -# image_url :string -# location :string -# topic_id :integer -# token_id :integer +# id :integer not null, primary key +# verse_id :integer +# chapter_id :integer +# position :integer +# text_madani :text +# text_indopak :text +# text_simple :text +# verse_key :string +# page_number :integer +# class_name :string +# line_number :integer +# code_dec :integer +# code_hex :string +# code_hex_v3 :string +# code_dec_v3 :integer +# char_type_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# pause_name :string +# audio_url :string +# image_blob :text +# image_url :string +# location :string +# topic_id :integer +# token_id :integer +# char_type_name :string # class Word < ApplicationRecord diff --git a/lib/tasks/translation.rake b/lib/tasks/translation.rake index d72d2f0d..047c98e8 100644 --- a/lib/tasks/translation.rake +++ b/lib/tasks/translation.rake @@ -1,20 +1,24 @@ namespace :translation do task import: :environment do - #NOTE: place file(translation.txt) in rake directory, fill these variables and ran the rake task to import translation. Each line should have single verse translation in order + #NOTE: place file(translation.txt) in tasks directory, fill these variables and ran the rake task to import translation. Each line should have single verse translation in order # Its one time operation, index and performance don't count - author_name = "AbdolMohammad Ayati" - localized_name="Абдулмуҳаммади Оятӣ" - language = Language.find(160) #Tajik - data_source = DataSource.where(name: 'Tanzil Project').first_or_create + author_name = "Mustafa Khattab" + localized_name="Mustafa Khattab" + language = Language.find_by_iso_code('en') #English + data_source = DataSource.where(name: 'Quran.com').first_or_create - author = Author.create(name: author_name) + author = Author.where(name: author_name).first_or_create if localized_name author.translated_names.where(language: language).first_or_create(name: localized_name) end - resource_content = ResourceContent.where(data_source: data_source, cardinality_type: ResourceContent::CardinalityType::OneVerse, sub_type: ResourceContent::SubType::Translation, resource_type: ResourceContent::ResourceType::Content, language: language, author: author, author_name: author.name).first_or_create + resource_content = ResourceContent.where(data_source: data_source, cardinality_type: ResourceContent::CardinalityType::OneVerse, sub_type: ResourceContent::SubType::Translation, resource_type: ResourceContent::ResourceType::Content, language: language, author: author).first_or_create + resource_content.author_name = author.name + resource_content.name = author.name + resource_content.language_name = language.name resource_content.approved = false #varify and approve after importing + resource_content.slug = "#{language.iso_code}_#{author.name.underscore.gsub(/(\s)+/, ' ').gsub(' ', '_')}" resource_content.save lines = [] @@ -25,9 +29,15 @@ namespace :translation do if Verse.count != lines.count raise("Invalid file, file should have #{Verse.count} lines") end - + Verse.unscoped.order('verse_index asc').each_with_index do |verse, i| - verse.translations.where(language: language, resource_content: resource_content).first_or_create(text: lines[i]) + trans = verse.translations.where(language: language, resource_content: resource_content).first_or_create + trans.text = lines[i] + trans.language_name = language.name + trans.resource_name = resource_content.name + trans.save end + + puts "Done importing translation. Resource id: #{resource_content.id}" end end diff --git a/spec/models/resource_content_spec.rb b/spec/models/resource_content_spec.rb index db8ef19e..54b37aeb 100644 --- a/spec/models/resource_content_spec.rb +++ b/spec/models/resource_content_spec.rb @@ -16,6 +16,7 @@ # language_name :string # created_at :datetime not null # updated_at :datetime not null +# slug :string # require 'rails_helper' diff --git a/spec/models/tafsir_spec.rb b/spec/models/tafsir_spec.rb index 6fe3d912..13fb6d3a 100644 --- a/spec/models/tafsir_spec.rb +++ b/spec/models/tafsir_spec.rb @@ -11,6 +11,7 @@ # created_at :datetime not null # updated_at :datetime not null # resource_name :string +# verse_key :string # require 'rails_helper' diff --git a/spec/models/word_spec.rb b/spec/models/word_spec.rb index ea144ef5..33f7eac0 100644 --- a/spec/models/word_spec.rb +++ b/spec/models/word_spec.rb @@ -2,31 +2,32 @@ # # Table name: words # -# id :integer not null, primary key -# verse_id :integer -# chapter_id :integer -# position :integer -# text_madani :text -# text_indopak :text -# text_simple :text -# verse_key :string -# page_number :integer -# class_name :string -# line_number :integer -# code_dec :integer -# code_hex :string -# code_hex_v3 :string -# code_dec_v3 :integer -# char_type_id :integer -# created_at :datetime not null -# updated_at :datetime not null -# pause_name :string -# audio_url :string -# image_blob :text -# image_url :string -# location :string -# topic_id :integer -# token_id :integer +# id :integer not null, primary key +# verse_id :integer +# chapter_id :integer +# position :integer +# text_madani :text +# text_indopak :text +# text_simple :text +# verse_key :string +# page_number :integer +# class_name :string +# line_number :integer +# code_dec :integer +# code_hex :string +# code_hex_v3 :string +# code_dec_v3 :integer +# char_type_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# pause_name :string +# audio_url :string +# image_blob :text +# image_url :string +# location :string +# topic_id :integer +# token_id :integer +# char_type_name :string # require 'rails_helper'