NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

//
// ViewController.swift
// DictionaryServiceClient,
//
// Created by student on 11/06/2022.
// Copyright © 2022 PL. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource {
var srcLanguageNames: Array<String> = Array<String>()
var dstLanguageNames: Array<String> = Array<String>()
let baseUrl = "https://od-api.oxforddictionaries.com:443/api/v2/translations"
let appId = "684d2eba"
let appKey = "50dc5e44b09f129878287a3644a1ba26"

let srcLanguageDict: [String: String] = [
"English": "en",
"Spanish": "es",
"Lamnso": "nso",
"isiZulu": "zu",
"Urdu": "ur",
"German": "de",
"Portuguese": "pt"
]

let dstLanguageDict: [String: String] = [
"English": "en",
"Spanish": "es",
"Lamnso": "nso",
"isiZulu": "zu",
"Urdu": "ur",
"German": "de",
"Portuguese": "pt"
]

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.

self.srcLanguage.delegate = self
self.srcLanguage.dataSource = self

self.dstLanguage.delegate = self
self.dstLanguage.dataSource = self

srcLanguageNames = Array<String>(srcLanguageDict.keys).sorted()
dstLanguageNames = Array<String>(dstLanguageDict.keys).sorted()

srcLanguageDict.keys.sorted(by: {$0.localizedStandardCompare($1) == .orderedAscending})

dstLanguageDict.keys.sorted(by: {$0.localizedStandardCompare($1) == .orderedAscending})

}


@IBOutlet var srcLanguage: UIPickerView!
@IBOutlet var dstLanguage: UIPickerView!

@IBOutlet var textSrc: UITextField!

@IBOutlet var textDest: UITextField!

func numberOfComponents(in pickerView: UIPickerView) -> Int{
return 1;
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{
if pickerView == srcLanguage{
return srcLanguageNames.count
}
return dstLanguageNames.count
}

var srcLangPicked = "";
var dstLangPicked = "";

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {

if pickerView == srcLanguage{
srcLangPicked = srcLanguageNames[row]
return srcLangPicked

}else{
dstLangPicked = dstLanguageNames[row]
return dstLangPicked
}
}

func makeTranslateRequest(urlString: String, appId: String, appKey: String, srcLang: String, dstLang: String, word: String){

let url = URL(string: urlString+"/"+srcLang+"/"+dstLang+"/"+word+"?strictMatch=false&fields=translations")!
print(url)
var request = URLRequest(url: url)
request.addValue("application/json", forHTTPHeaderField: "accept")
request.addValue(appId, forHTTPHeaderField: "app_id")
request.addValue(appKey, forHTTPHeaderField: "app_key")


var dstWord = ""

URLSession.shared.dataTask(with: request, completionHandler: { data, response, error in
if let response = response,
let data = data,

let welcome = try? JSONDecoder().decode(Welcome.self, from: data){

let results = welcome.results
for i in 0...results.endIndex-1 {
let result = results[i]
if result.language==self.srcLanguageDict[self.srcLangPicked]{
let lexicalEntries = result.lexicalEntries
for j in 0...lexicalEntries.endIndex-1{
let lexicalEntry = lexicalEntries[j]
let entries = lexicalEntry.entries
for k in 0...entries.endIndex-1{
let entry = entries[k]
let senses = entry.senses
for l in 0...senses.endIndex-1{
let sense = senses[l]
let translations = sense.translations
for m in 0...translations.endIndex-1{
let translation = translations[m]
print(response)

if dstWord == "_"{
dstWord = translation.text
DispatchQueue.main.async{
self.textDest.text = dstWord
}
}
}
}
}
}
}
}
}

}).resume()

}

@IBAction func pushTranslateButton(_ sender: UIButton) {

makeTranslateRequest(urlString: baseUrl, appId: appId, appKey: appKey, srcLang: srcLanguageDict[srcLangPicked]!, dstLang: dstLanguageDict[dstLangPicked]!, word: textSrc.text!)
}

}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.