Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you want is the current language locale, the following code should return the code:</p> <pre><code>NSArray *languagesArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]; NSString *currentLanguage = [languagesArray objectAtIndex:0]; </code></pre> <p>You can then do the following</p> <pre><code>[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.lproj/mydatabase.db", currentLanguage]]; </code></pre> <p>You may want to check if the path exists and is a valid file, if not maybe use some default path like the one for English (en.lproj)</p> <p>Edit: There is another way you can do this using NSLocale's preferred languages because then you get a list of the preferred languages, so some updated code for the first bit would be:</p> <pre><code>NSArray *languagesArray = [NSLocale preferredLanguages]; NSString *currentLanguage = [languagesArray objectAtIndex:0]; </code></pre> <p>In the end, you'd end up with something like so:</p> <pre><code>NSString *pathComponent = [NSString stringWithFormat:@"%@.lproj/mydatabase.db", currentLanguage]; NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:pathComponent]; NSString *activePath = nil; // This will store the active language file // Check if the file exists... if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { activePath = path; } else { activePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"en.lproj/mydatabase.db"]; // Fallback } </code></pre> <p>Please note, the above code is untested but should suffice. You may need to modify it a little...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload