I'm currently working on an iOS project in Xcode where I've created a resource bundle containing a translated .strings file (let's call it myTexts.strings). This bundle is then reused in multiple targets (as I plan to add multiple translation files, to better separate specific app areas).
When I try to access a localized string with the following line of code:
NSLocalizedString(key, tableName: "myTexts", bundle: bundle, comment: comment)
The string is never found. Additionally, when I attempt to list the available .strings files with the following code:
bundle.paths(forResourcesOfType: "strings", inDirectory: nil)
It only returns the file in en.proj
, even though the app is running in Czech language (i.e., I expect to see cs.proj
).
However, when I remove the bundle, include the .strings file directly in all targets, and run the app on a device set to Czech, it works perfectly fine — the bundle.paths(forResourcesOfType: "strings", inDirectory: nil)
function correctly lists cs.proj, and the czech string is correctly looked up.
I've checked the structure of my bundle and ensured that it contains the cs.lproj directory. The built app also has the *.lrpoj for all the languages. I'm also confident that I'm initializing my bundle object correctly, using the path to the resource bundle:
let bundlePath = Bundle.main.path(forResource: "TheBundleName", ofType: "bundle")
let bundle = Bundle(path: bundlePath!)
Despite all this, I'm still encountering the problem. I'm curious to understand why this is happening and what I can do to make it work with the bundle. Any insights or suggestions would be greatly appreciated. Thanks!