Search code examples
ioswordpressswift3translate

Translate UITextField input text into Spanish runtime


An iOS app which displaying wordpress blogs. There is search feature, App searches world-phress into API's data. Wordpress website contents are in Spanish language.

My issue is when user inputted text "Buho", app should search "Búho", "Buho", "buho", "búho" in Spanish data and display result according. Curretnly app is matching word "buho", not "búho".

On Wordpress website, same thing is possible, User can search either "Búho" or "Buho", all search result displayed.

How to translate UITextField's text value into Spanish, So I can easily search into NSArray and show result. Or is it possible to replace character set?

Simple english word searching is possible using NSArray filter, search into blog's title and text with particular text.

Like this:

let searchingWorld = self.searchBar.text!.lowercased()
let blogSearchResult = self.blogs.filter{ $0.title.lowercased().contains(searchingWorld) || $0.text.lowercased().contains(searchingWorld) || $0.tags.contains(searchingWorld) || $0.categories.contains(searchingWorld) }

self.blogs object is array of dictionary type object. {title, text, category, tags} Not found any solution.

Any help greatly appreciated.

Punita


Solution

  • If I understand you correctly, you're not looking to translate to Spanish, but are looking how to do a so called diacritic insensitive search.

    iOS has a search option to do that.

    In the same way you can specify an option to do a case insensitive search.

    Here're is an example that I hope helps.