iOS internationalization and genstrings localization strings for all subdirectories

Source: Internet
Author: User

iOS internationalization and genstrings localization strings for all subdirectories
Recently busy in a foreign project, every day overtime, no time to update the blog. Simply talk about the international knowledge.
First, we use a string that must be nslocalizedstring (key,comment), This allows us to specify different values for the key in different localizable.strings, and the system will look for different strings according to the current system language and different lproj. 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. Examples are as follows:
This allows the program to choose "Login" or "log in" according to the system language.

But if you add a localized string each time, you have to manually go to the localizable.strings adding the corresponding key, it is too troublesome, fortunately, Apple provides a shortcut to generate localized key command. The following is an example of en.lproj generation:
First, we enter the directory where the program works, and we build en.lproj with commands.
mkdir en.lproj
We then traverse through all the subdirectory files to generate the Localizable.strings command as follows:
Find./-name *.m-print0 | xargs-0 Genstrings-o En.lproj
(basically said Genstrings-o en.lproj *.m can generate localizable.strings, but this command can only generate the current directory, and does not traverse subdirectories, so it is useless)
This way the system will use the key value of the Nslocalizedstring function in the directory to write to the file.
It should be noted that nslocalizedstring (key,comment), when using this function, key cannot be a macro definition or some dynamic string, otherwise the above command will error.

Today back to do internationalization, found that the above command is only to traverse the. m file, but the actual discovery often has strings placed in the. h file, so you should use the following command to traverse the entire. h and. m files, specifically to add:
Find. \ (-name ' *.m '-o-name ' *.h ')-print0 | xargs-0 Genstrings-o En.lproj

Finally, it is necessary to standardize the sentence. If your previous code was useless to nslocalizedstring, it would be troublesome.

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.