ios - Internationalization UIButton -


i have button , after press them want play audio.the name of button name of audio file

private func playaudio(title : string){     audioplayer = avaudioplayer(contentsofurl: nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource(title, oftype: "wav")!), error: nil)     isplayng = true     audioplayer.play() }  @ibaction func soundbutton (sender: uibutton){     if let title = sender.currenttitle{         switch title {         case "stop":             if isplayng{             audioplayer.stop()             }         default:             playaudio(title)         }     } } 

so if localise stoyboard title different , crash because there no audio file.so there way can without duplicating audio files.

this naive implementation, maybe can give ideas: keep actual file names , localized file names in dictionary (and maybe store them in plist file first load them when appp launches) , actual file name localized title:

let filestitles = ["file one": "file1.wav", "fichier un": "file1.wav", "archivo uno": "file1.wav"] // etc  @ibaction func soundbutton (sender: uibutton) {     if let title = sender.currenttitle {         switch title {         case "stop":             if isplayng{                 audioplayer.stop()             }         default:             // if title `file one` filename `file1.wav`             let filename = filestitles[title]             playaudio(filename)         }     } } 

it's simple dictionary in example, can choose way like, idea being create table localized titles correspond actual file title.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -