programming4us
programming4us
MOBILE

Windows Phone 7 Development : Using Culture Settings with ToString to Display Dates, Times, and Text

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
2/23/2011 9:26:22 AM
To see how you can go about preparing an application for the world, you'll build a simple application that announces a new product, in this case a Windows Phone. But first, you will learn how to use the CultureInfo class to ensure dates, numbers, and text appear in the right form regardless of the culture in which the announcement is made. Then you'll see how, by using resource (.resx) files, you can easily add translated content to your app to reach new markets.

Let's jump into code that will set the stage for our discussion of internationalization of Windows Phone 7 applications.

  1. Let's start by creating a new project inside Visual Studio and naming it InternationalizationSample.

By default, the MainPage.xaml file is created in the application, with the designer and XAML windows open and ready to program.

  1. Double-click MainPage.xaml to bring up the XAML designer window. For convenience and simplicity, we will alter the content of textblocks in the TitleGridTitleGrid look identical to the XAML here. block. Make the XAML of the

<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="24,24,0,12">
<TextBlock x:Name="ApplicationTitle" Text="Current Culture Setting" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="culture" Margin="-3,-8,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>


Your project should now look like Figure 12-1. So far you've simply changed the text of the default title textblock in the Windows Phone 7 application.

  1. Now double-click MainPage.xaml.cs to bring up the code view. Alternately, you can right-click the MainPage.xaml file and select "View Code."

  2. Add the following statement to the top of the MainPage.xaml.cs file:

    using System.Globalization;

  3. Paste the following code in the MainPage() constructor:

    PageTitle.Text = CultureInfo.CurrentCulture.ToString();

  4. Press F5 to run the application. .

This caption represents two parts of the current Culture setting on Windows Phone 7. The first part—"en"—states that the English language is the current language on this Windows Phone 7 device (or device emulator in our case) and it is a part of an ISO standard to represent culture code associated with the language. The second part—"US"—represents that the current locale is the United States, and indicates that dates, currency, and other region-specific items should be shown in the format that is native to people in the United States. That part is an ISO standard as well, to represent a subculture code associated with a country or region.

A concept of culture in .Net Framework refers to a set of user preferences specific to the user, such as dates, currency, and calendar format. Besides CurrentCulture, the CultureInfo class contains many properties that may be of interest to you as you internationalize your applications; you can find the full list here: http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo_properties.aspx. For instance, we could have used the DisplayName property to show a friendlier description of the current culture (in our case, we would get "English (United States)." As has already been mentioned, there is a lot of material to cover when it comes to internationalization—a good place to refer to for more information is MSDN documentation of the System.Global namespace, which can be found here: http://msdn.microsoft.com/en-us/library/abeh092z.aspx.

You might think that the locale setting is of minor importance, yet it is extremely important to properly localize your application: in England, for instance, people speak English (certainly!), but the numeric date format is "dd/mm/yyyy," where the "dd" is the numeric representation of the day, "mm" is the numeric representation of the month, and "yyyy" is the numeric representation of the year. Compare this to the United States, where people speak English as well, but for numerical date representations, the month comes first! It would be very time-consuming to keep track of all possible localization issues that may arise. In the end, we are also very likely to make mistakes. It is much easier to stand on the shoulders of giants who have thought through many internationalization issues and have made standard libraries and functions available for our use. Our main task is to make sure to use those libraries.

Figure 1. Preparing the phone design surface for the internationalization demo

Other  
  •  Mobile Application Security : SymbianOS Security - Persistent Data Storage
  •  Mobile Application Security : SymbianOS Security - Interprocess Communication
  •  Mobile Application Security : SymbianOS Security - Permissions and User Controls
  •  Windows Phone 7 Development : Building a Trial Application (part 3) - Verifying Trial and Full Mode & Adding Finishing Touches
  •  Windows Phone 7 Development : Building a Trial Application (part 2) - Connecting to a Web Service & Adding Page-to-Page Navigation
  •  Windows Phone 7 Development : Building a Trial Application (part 1) - Building the User Interface
  •  jQuery 1.3 : Table Manipulation - Sorting and paging (part 2) : Server-side pagination & JavaScript pagination
  •  jQuery 1.3 : Table Manipulation - Sorting and paging (part 1) : Server-side sorting & JavaScript sorting
  •  Windows Phone 7 Development : Understanding Trial and Full Modes (part 3) - Simulating Application Trial and Full Modes
  •  Windows Phone 7 Development : Understanding Trial and Full Modes (part 2) - Using the Marketplace APIs
  •  
    Top 10
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
    - Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
    - Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    programming4us programming4us
    programming4us
     
     
    programming4us