How to programmatically use the language translation function in iOS? [Swift 5] - ios

I am aware that there is a Translate function in a text menu in UITextView in iOS
(see for example Remove Translate and share options from selection menu on textview in xamarin).
I would like to use this function by myself without using the Translate menu. For example, I would like to translate an entire sentence displayed in a UITextView instead of translating only the selected parts.
Is there a specific func that we can use? How can I call this function?

Apple's translate API is not available to the public.
https://developer.apple.com/forums/thread/650024
You can use Google's GoogleMLKit/Translate instead.
Use ML Kit on iOS.
Add GoogleMLKit/Translate in your podfile by running the following command in the terminal.
pod 'GoogleMLKit/Translate', '3.1.0'
Read the Instal & Getting started sections on https://cocoapods.org/ if you have not set cocoapods or you do not know how to do so.
Google has written a very good sample code. It is straight forward.
Read from the Translate a string of text section onwards.
https://developers.google.com/ml-kit/language/translation/ios
info:
You may find this link helpful.
https://maximbilan.medium.com/googletranslate-api-in-swift-a36489a84508

Related

Ignore spelling API in electron 8

With the release of electron 8, I was implementing the newly released spell check API's on my electron app. The context menu should look similar to this:
I was able to implement learn spelling using ses.addWordToSpellCheckerDictionary API given in docs, however I am stuck trying to implement the ignore spelling part.
The difference between the two according to google is
Ignore spelling
The word is ignored if it occurs again in the document (it will be highlighted in other documents)
Learn Spelling
The word won't be flagged as misspelled in any document.
I can implement it such a way that the dictionary suggestions are not shown for a specific set of words stored in array, but that will still leave a red squiggly line below the word. Besides, there has to be a native API call implemented given spell check has been officially announced.
I could have simply used webFrame.setSpellCheckProvider, but then I would have to hard-code a language, add boilerplate code, use a node module.
Try instead using electron-spellchecker npm package:
It has an:
Option to ignore a word at runtime only.

Seismograph Chart in Swift

I am creating a seismic recording app in IOS. I want to show seismograph chart in my app like . I have searched a lot on google and github but unable to find EXACTLY same visual. I am currently using "Charts" library from github but it is not producing same visual effect. Please suggest me just name of library.
use LineChartView of this {https://github.com/danielgindi/Charts} library. By default your view will not resemble to seismograph but you need to customise it. To do this, whenever you add a point to graph, also add the point of same value but negative value. For example you want to show an earth-quake of magnitude 5. You should add a point of value 5. At the same time also add a point of value -5. This will give view like seismograph. If you can’t understand then reply, I will provide you code for doing this.
What about this https://github.com/vegather/GraphView ?
It will not compile unless you build against a device (even a generic one) because it uses metal.

AutoComplete Google Places in a Textfield in IOS

I have a UITextField and a UITableView under the UITextField.
When user enter anyplace it show the relevant places to the data which user right should be shown in the table view. For this I have search a lot to the third party lib's and follow step by step procedure of google but failed to get the results.
Now again I have tried the Google Developers procedure but not results so far, I have got API key in my AppDelegate.m file and done some coding in my view controller where I want to show.
I'm just messed up how to get my result, can anyone help me?
I'm getting this issue I don't know why because I have only used Objective-c code in my project from Google Developers.
the issue is this:
"Swift Language Version” (SWIFT_VERSION) is required to be configured
correctly for targets which use Swift. Use the [Edit > Convert > To
Current Swift Syntax…] menu to choose a Swift version or use the Build
Settings editor to configure the build setting directly"
Maybe one of the Frameworks you are using was Swift. So check each and every Framework you have dragged to your project.
If you are using CoreData you need to change Code Generation to Objective-C too if it was selected as Swift.
Find out more Here

Is there any easiest way to implement all required methods of protocol in iOS?

First of all it's not the duplicate of this question because i couldn't find any discussion about offline documentation, suitable answers and about future release of updates in Xcode there.
Actually I am from android and java background and currently starting to develop iOS apps too. As we all know we use to implement all methods of an Interface easily with the help of suggestions given in IDE by pressing Alt + Enter.
And here in the iOS we have to see the reference each time and search for all required & optional methods, and implement them manually one by one which consumes times It's fine for a moment But
My Questions are :
Is there Any easiest way to view all required method at first lookup in documentation OR implement all required methods of protocol with the help of IDE ?
Is it possible that we will get this feature in future release of Xcode's update ?
I can't be ensure availability of Internet all the time, And How can I see the documentation at that time ?
Just go ahead and declare that your class adopts the protocol in question.
Xcode will point the error if you fail to implement any of the required methods:
From the list under the disclosure triangle (items with gray "!" icons), you can get a hint of the names of the missing methods. You can start to type and autocomplete will do the rest.
Update for Xcode 9:
It looks like now, you can auto-fill the methods with one click:
Refactoring
Rename a symbol in a single file or in a project across Swift, C, Objective-C, C++ files, and Interface Builder files.
View all the possible changes in one editor pane.
Convert method signatures between Swift and Objective-C formats.
Update properties, getters, setters, and synthesized iVars as needed.
Apply a fix-it everywhere with one button.
Automatically fill in missing cases in switch statements, and mandatory methods for protocol conformance with one click.
Extract method functionality for all supported languages, along with other language-specific local refactoring.
(emphasis mine)
And indeed:
Clicking "Fix" adds the necessary method stubs.
Go to Xcode -> preferences(on top-left corner) -> downloads -> here you will see list of items that can be downloaded. Download the documentation for iOS x.x version. So now, whenever you are offline.. you can go to help(top bar in window) -> documentation and search for whole ios documentation.. all the development guides etc

Having a language select option in an app using Swift

I have Googled this for hours but could find no advice for the following problem (using Swift).
I have seen in many apps an option to select the language from inside the app like this:
(source: unity3d.com)
I would like to achieve something similar, but am having trouble implementing it. I have localized my app and have my Localizable.strings files all set up. I'd imagine it has something to do with storing the language selected in NSUserDefaults, but how can I make the app use the appropriate Localizable.strings file once a language has been chosen? Or is that the wrong way to approach it?
How have others successfully implemented this feature in Swift?
I've already faced this issue on one of my project and found one solution :
When the user select a language from a list, post a NSNotification. All your UIViewController subclass must register to this notification and change the labels value according to the new language selected.
You can use the localized strings in order to set the labels, but NSLocalizedString(...) shouldn't be called since it's relying on the device language which is different from the application language.
You can find my implementation of a custom localisator on Github, available both on Swift and objective-C.

Resources