iOS internationalization and genstrings localization strings for all subfolders

Source: Internet
Author: User

iOS internationalization and genstrings localization strings for all subfolders
In a recent busy external project. Work overtime every day. There is no time to update the blog. Simply talk about the internationalization of knowledge.

  
First, we use strings. Must be nslocalizedstring (key,comment), so we are different localizable.strings specify different values for key, the system will be based on the current system language. Go to different lproj to find a different string. Show it in a picture:

Our app only supports Chinese, English, so only zh-hans.lproj and en.lproj are built, then different values are specified in Localizable.strings. The proportions are as follows:
This allows the program to select "Login" or "log in" according to the system language.

But assuming that each time you add a localized string, you have to manually go to localizable.strings to add the corresponding key, it is too troublesome, fortunately, Apple provides a shortcut to generate localized key commands. The following is an example of en.lproj generation:
First, we go to the folder where program project is located and use the command to build en.lproj
mkdir en.lproj
Then we traverse through all the subfolder files. To generate localizable.strings, commands such as the following:
Find./-name *.m-print0 | xargs-0 Genstrings-o En.lproj
(basically all say genstrings-o en.lproj *.m can generate localizable.strings. However, this command can only generate the current folder. does not traverse subfolders. So basically useless)
This way the system will use the key value of the Nslocalizedstring function in the folder to write to the file.
It is important to note that nslocalizedstring (key,comment). When using this function, key cannot be a macro definition or some dynamic string, otherwise the command above will cause an error.

Once again today to do internationalization, found that the above command is only able to traverse the. m file. But the actual discovery often has strings placed in the. h file. Therefore, you should use the following command to traverse the entire. h and. m files, and the purpose of this is to add:
Find. \ (-name ' *.m '-o-name ' *.h ')-print0 | xargs-0 Genstrings-o En.lproj

Finally, the standardization is very necessary. If you have never used the code nslocalizedstring. That would be a problem.



iOS internationalization and genstrings localization strings for all subfolders

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.