I am working on a multi language app. This app includes some sound files. For examples if users system language is English, when user click on apple icon, pronunciation of "apple" name will play from /base.lproj/apple.mp3 file. if users system language is Turkish, pronunciation of "apple" name will play in Turkish from /tr.lproj/apple.mp3 file.
Localizable.string, Main.string, InfoPlist.strings and all sound files are localized and project is working fine at simulator.
However when we come to real device to test, sound files are not localized according to system language. and only play base language (English) sound file.
I think I found problem but I dont know the solution.
To play sound, first i found sound URL like that:
let path = Bundle.main.path(forResource: name, ofType: "mp3")
print(path)
let soundURL = URL(fileURLWithPath: path!)
When i print sound url in simulator, simulator finds correct sound file according to language:
/Bundle/Application/.../tr.lproj/apple.mp3" //Applang: Turkish - Play Tur
/Bundle/Application/.../base.lproj/apple.mp3" //Applang: System - Play Eng
But when i print sound url in real device which language is Turkish, it finds base language file (English) and print this path.
/Bundle/.../grapefruit.mp3" // where is tr.lproj ?
Again Localizable.string (Turkish), Main.string(Turkish), InfoPlist.strings(Turkish) work good and show text correctly in their own langauge on real device.
According to Apple Document
path(forResource:ofType:) : The method first looks for a matching resource file in the non-localized resource directory of the specified bundle. If a matching resource file is not found, it then looks in the top level of an available language-specific .lproj folder.
so i understand that i should use another path method
path(forResource:ofType:inDirectory:forLocalization:)
and specified my code like that
let path = Bundle.main.path(forResource: name, ofType: "mp3",inDirectory:"tr.lproj",forLocalization:"tr")
Is there any other way for localized sound files properly in device? Or should i use path(forResource:ofType:inDirectory:forLocalization:) method and build some logical code. (check system language etc)