On iPhone NSLocalizedString
returns the string in the language of the iPhone.
Is it possible to force NSLocalizedString
to use a specific language to have the app
in a different language than the device ?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
Swift Version:
The trick to use specific language by selecting it from the app is to force the
NSLocalizedString
to use specific bundle depending on the selected language ,here is the post i have written for this learning advance localization in ios apps
and here is the code of one sample app advance localization in ios apps
Do not use on iOS 9. This returns nil for all strings passed through it.
I have found another solution that allows you to update the language strings, w/o restarting the app and compatible with genstrings:
Put this macro in the Prefix.pch:
and where ever you need a localized string use:
To set the language use:
Works even with consecutive language hopping like:
In file .pch to define:
This function will try to get localized string for current language and if it's not found it will get it using english language.
Based on Tudorizer's answer to change language without leaving or restarting the application.
Instead of a macro, use a class for accessing the preferred language in order to check if a specific language code is present.
Below is a class used to obtain the current language bundle that is working for iOS 9:
Use the class above to reference a string file / image / video / etc:
Change language in-line like below or update the "changeCurrentLanguage" method in the class above to take a string parameter referencing the new language.