After a perverted demand, to switch program language within the program to achieve internationalization.
Can look at this first, more detailed.
http://blog.csdn.net/xwren362922604/article/details/17190061
After reading the question came,
1, the project inside a large number of xib or storyboard inside the UI set the text, how to enable them to dynamically load the language "non-set system language Restart"
2, a simple idea when the code triggers the switching language to send a notification to let the Viewcontroller in memory refresh the text of the UI. [In the project so all VC every add not exhausted]
All next can be perfected.
1, toggle the language, reload the window's root view. According to different languages. "Search the Internet for storyboard internationalization"
You will find that after you operate Xcode added three files to main storyboard
This is the rationale here. Base and the language you added.
You right-click the show in Finder on these files.
See those three folders. Lproj here is the resource file for the corresponding language. You switch the language is to get the current language eg:en spelling path en.lproj
[[NSBundle mainbundle] pathforresource: userlanguage ofType:@ "Lproj"];
Obtained by Path
NSBundle
familiar with it. Inside this thing is the resource file that our program needs. It's actually the Xx.lproj folder.
Initialization
[Uistoryboard storyboardwithname:@ "Main" bundle: bundle];
We are more accustomed to the following parameters of the taste nil.
There's a problem with that. In fact, the real main is placed in the base folder. The program jumped. Let's get rid of base. Never delete the base file directly. So directly to the main. Storyboard deleted it.
Over here
Point file. Right column. Remove the base ditch. No warning.
Look again
It's ok now. In two folders respectively.
Legacy Issue: If you support many languages, the program will become very large. There is a solution to the exchange of
2, write a VC base class. Registration and removal notifications. For automatically refreshing the UI within the VC. You can add the number group variable "Blok" in the base class
In SUBVC, note here to prevent circular references. _weak
In SUPERVC
Traversal execution.
Implement automatic refresh
You can download the project here:
git clone [email protected]: Githhhh/test_local_two.git
Done