Use of monotouch software in multiple languages

Source: Internet
Author: User

This article describes how to implement software in monotouch that supports multiple languages and localize in different environments, that is, for international users.

Create a project in monodevelop, C # -- momotouch -- iPhone -- single view application, name it localization01, and add the new folder en in the root directory. lproj: name the new file localizable. strings, which is the added English language. It is similar to adding French and Spanish. Name the folder Fr. lproj and es. in the lproj folder, add the new file named localizable. strings. The name must be consistent with the above, so that the software can find the corresponding local resources based on the language in the Apple device settings.

Make sure that the localizable. Strings file is used. Right-click the selected file and choose build action to set it to content. Otherwise, you will not be able to implement localization. Remember. At the beginning, I fell in front of it and debugging took a long time.

The localizedstrings () method and pathforresource () method are used to implement localization. The former is to load the local string from the. Strings file. The latter is the path for loading the corresponding image (or other file types) in the localized folder.

The Code is as follows:

1. design the form in xcode as follows:

 

2. The background code is implemented as follows:

View code

 1  public override void ViewDidLoad() { 2                                 base.ViewDidLoad(); 3                                  4             LocaleLabel.Text=NSLocale.CurrentLocale.LocaleIdentifier; 5             LanguageLabel.Text=NSLocale.PreferredLanguages[0]+"Lan"; 6  7             GoodbyeLabel.Text=NSBundle.MainBundle.LocalizedString("Hello","a greeting"); 8             Segments.SetTitle(NSBundle.MainBundle.LocalizedString("One","Number one"),0); 9             Segments.SetTitle(NSBundle.MainBundle.LocalizedString("Two","Number two"),1);10             Segments.SetTitle(NSBundle.MainBundle.LocalizedString("Three","Number three"),2);11 12             OkButton.SetTitle(NSBundle.MainBundle.LocalizedString("OK","affirmative"),UIControlState.Normal);13         //    OkButton.SetTitle(NSBundle.MainBundle.LocalizedString("OK (unavailable)","affirmative disabled"),UIControlState.Disabled);14             CancelButton.SetTitle(NSBundle.MainBundle.LocalizedString("Cancel","cancle button"),UIControlState.Normal);15             16 }

3. The code in the three localizable. Strings files is as follows:

1) en. lproj:

View code

1 "Hello" = "Hello";2 "Goodbye" = "Good-bye";3 "OK" = "OK";4 "Cancel" = "Cancel";5 "One" = "One";6 "Two" = "Two";7 "Three" = "Three";

2) es. lproj:

View code

1 /* A greeting */2 "Hello" = "Hola";3 "Goodbye" = "Adiós";4 "OK" = "Si";5 "Cancel" = "Cancelar";6 "One" = "Uno";7 "Two" = "Dos";8 "Three" = "Tres";

3) In Fr. lproj

View code

 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 3 <plist version="1.0"> 4 <dict> 5     <key>Hello</key> 6     <string>Bonjour</string> 7     <key>Goodbye</key> 8     <string>Au revoir</string> 9     <key>OK</key>10     <string>Oui</string>11     <key>Cancel</key>12     <string>Annuler</string>13     <key>One</key>14     <string>un</string>15     <key>Two</key>16     <string>deux</string>17     <key>Three</key>18     <string>trois</string>19 </dict>20 </plist>

We can see from the above that there are two ways to explain the localization language.

Related Article

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.