diff --git a/src/tatoeba/sentence.gleam b/src/tatoeba/sentence.gleam index fd9df58..b4a3ecb 100644 --- a/src/tatoeba/sentence.gleam +++ b/src/tatoeba/sentence.gleam @@ -215,6 +215,11 @@ pub type Translation { language_tag: String, /// The full name of the language the translation is written in. language_name: String, + /// Whether the translation has been created for a standalone sentence, i.e. not + /// a translation of a translation. + is_direct: Option(Bool), + /// The direction of writing in the sentence. + writing_direction: WritingDirection, /// Represents how reliable the translation is. /// /// Note: This value is reported by Tatoeba as not currently being in use. @@ -239,6 +244,8 @@ fn translation( use language <- result.try(data |> field("lang", optional(string))) use language_tag <- result.try(data |> field("lang_tag", string)) use language_name <- result.try(data |> field("lang_name", string)) + use is_direct <- result.try(data |> optional_field("isDirect", bool)) + use writing_direction <- result.try(data |> field("dir", writing_direction)) use correctness <- result.try(data |> field("correctness", int)) use script <- result.try(data |> field("script", optional(string))) use transcriptions <- result.try( @@ -252,6 +259,8 @@ fn translation( language: language, language_tag: language_tag, language_name: language_name, + is_direct: is_direct, + writing_direction: writing_direction, correctness: correctness, script: script, transcriptions: transcriptions, @@ -413,7 +422,7 @@ pub type Sentence { /// /// This value can be `None` in the case that a user is suspended or otherwise. owner: Option(User), - /// The direction of writing applied to the sentence. + /// The direction of writing in the sentence. writing_direction: WritingDirection, /// Indicates whether the sentence is favorited by the current user. /// diff --git a/test/sentence_test.gleam b/test/sentence_test.gleam index bb10d9c..79b5c8a 100644 --- a/test/sentence_test.gleam +++ b/test/sentence_test.gleam @@ -1,12 +1,8 @@ +import gleam/list import gleam/option.{None, Some} -import gleeunit import gleeunit/should import tatoeba/sentence -pub fn main() { - gleeunit.main() -} - pub fn new_id_test() { sentence.new_id(1) |> should.be_ok() @@ -55,38 +51,133 @@ pub fn sentence_removed_test() { } pub fn sentence_test() { - let assert Ok(id) = sentence.new_id(12_212_258) + let assert Ok(id) = sentence.new_id(1) let assert Ok(Some(sentence)) = sentence.get(id) - sentence.id |> should.equal(12_212_258) - sentence.text |> should.equal("This work is free of charge.") - sentence.language |> should.equal(Some("eng")) - sentence.language_tag |> should.equal("en") - sentence.language_name |> should.equal("English") - sentence.script |> should.equal(None) + sentence.id |> should.equal(1) + sentence.text |> should.equal("我們試試看!") + sentence.language |> should.equal(Some("cmn")) + sentence.language_tag |> should.equal("zh-Hant") + sentence.language_name |> should.equal("Mandarin Chinese") + sentence.script |> should.equal(Some("Hant")) sentence.license |> should.equal("CC BY 2.0 FR") - sentence.based_on_id |> should.equal(Some(5_686_783)) + sentence.based_on_id |> should.equal(None) sentence.correctness |> should.equal(0) sentence.translations + |> list.take(5) |> should.equal([ sentence.Translation( - id: 5_686_783, - text: "Această lucrare nu se plătește.", - language: Some("ron"), - language_tag: "ro", - language_name: "Romanian", + id: 433_979, + text: "لنحاول !", + language: Some("ara"), + language_tag: "ar", + language_name: "Arabic", + is_direct: Some(True), + writing_direction: sentence.RightToLeft, + correctness: 0, + script: None, + transcriptions: [], + audios: [], + ), + sentence.Translation( + id: 2_608_341, + text: "আমরা একবার চেষ্টা করেই দেখি!", + language: Some("ben"), + language_tag: "bn", + language_name: "Bengali", + is_direct: Some(True), + writing_direction: sentence.LeftToRight, + correctness: 0, + script: None, + transcriptions: [], + audios: [], + ), + sentence.Translation( + id: 2_604_674, + text: "Ad neɛreḍ!", + language: Some("ber"), + language_tag: "ber", + language_name: "Berber", + is_direct: Some(True), + writing_direction: sentence.LeftToRight, correctness: 0, script: None, transcriptions: [], audios: [], ), + sentence.Translation( + id: 760_627, + text: "Да пробваме!", + language: Some("bul"), + language_tag: "bg", + language_name: "Bulgarian", + is_direct: Some(True), + writing_direction: sentence.LeftToRight, + correctness: 0, + script: None, + transcriptions: [], + audios: [], + ), + sentence.Translation( + id: 826_600, + text: "Versuchen wir's!", + language: Some("deu"), + language_tag: "de", + language_name: "German", + is_direct: Some(True), + writing_direction: sentence.LeftToRight, + correctness: 0, + script: None, + transcriptions: [], + audios: [ + sentence.Audio( + id: 497_098, + is_external: None, + author: Some("quicksanddiver"), + attribution_url: Some("/en/user/profile/quicksanddiver"), + license: Some(""), + ), + ], + ), ]) sentence.user_sentences |> should.equal(None) sentence.list_ids |> should.equal(None) - sentence.transcriptions |> should.equal([]) + sentence.transcriptions + |> should.equal([ + sentence.Transcription( + id: 1_991_078, + text: "我们试试看!", + sentence_id: 1, + script: Some("Hans"), + transcription_type: sentence.AlternativeScript, + last_modified: "2020-05-13T15:11:29+00:00", + owner_id: None, + owner: None, + html: "我们试试看!", + markup: None, + info_message: "This alternative script was generated automatically.", + is_readonly: True, + needs_review: False, + ), + sentence.Transcription( + id: 1_554_809, + text: "Wo3men5 shi4shi5 kan4!", + sentence_id: 1, + script: Some("Latn"), + transcription_type: sentence.ForeignTranscription, + last_modified: "2019-10-18T19:16:22+00:00", + owner_id: Some(81_071), + owner: Some(sentence.User(claimed_native: None, username: "Yorwba")), + html: "Wǒmen shìshi kàn!", + markup: None, + info_message: "Last edited by Yorwba on October 18, 2019 at 7:16:22 PM UTC", + is_readonly: False, + needs_review: False, + ), + ]) sentence.audios |> should.equal([]) sentence.owner - |> should.equal(Some(sentence.User(claimed_native: None, username: "vxern"))) + |> should.equal(Some(sentence.User(claimed_native: None, username: "sysko"))) sentence.writing_direction |> should.equal(sentence.LeftToRight) sentence.is_favorite |> should.equal(None) sentence.is_owned_by_current_user |> should.equal(False)