Presentation is loading. Please wait.

Presentation is loading. Please wait.

Metropolia 2013 C# programming and .NET framework

Similar presentations


Presentation on theme: "Metropolia 2013 C# programming and .NET framework"— Presentation transcript:

1 Metropolia 2013 C# programming and .NET framework
8. Localize Metropolia 2013 C# programming and .NET framework

2 Metropolia 2013 C# programming and .NET framework
Globalization Globalization is the process of designing and developing an application that supports localized user interfaces and regional data for users in multiple cultures. In the .NET Framework, the CultureInfo class represents information about a specific culture. Metropolia 2013 C# programming and .NET framework

3 Metropolia 2013 C# programming and .NET framework
Localizability Localizability is an intermediate process for verifying that a globalized application is ready for localization. An application is ready for localization if the application's executable code has been clearly separated from the application's localizable resources. Metropolia 2013 C# programming and .NET framework

4 Metropolia 2013 C# programming and .NET framework
System.Globalization The System.Globalization namespace contains classes that define culture-related information, including language, country/region, calendars in use, format patterns for dates, currency, and numbers, and the sort order for strings. Use these classes to simplify the process of developing a world-ready application. By passing a CultureInfo object representing the current culture to methods in this namespace, you can initiate the correct set of rules and data for the current user's culture. Metropolia 2013 C# programming and .NET framework

5 System.Globalization classes
Culture dependent classes calendars CompareInfo(string comparison) CultureInfo DateTimeFormatInfo Enumerations CalendarWeekRule CultureTypes DateTimeStyles Metropolia 2013 C# programming and .NET framework

6 Application Design Pattern
An application that is ready for localization is separated into two conceptual blocks, a block that contains all user interface elements and a block that contains executable code. The user interface block contains only localizable user-interface elements such as strings, error messages, dialog boxes, menus, embedded object resources, and so on for the neutral culture. The code block contains only the application code to be used by all supported cultures. The common language runtime supports a satellite assembly resource model that separates an application's executable code from its resources. Metropolia 2013 C# programming and .NET framework

7 Resources in Application
Nearly every production-quality application needs to use resources. A resource is any nonexecutable data that is logically deployed with an application. A resource might be displayed in an application as error messages or as part of the user interface. Resources can contain data in a number of forms, including strings, images, and persisted objects. Storing your data in a resource file allows you to change the data without recompiling your entire application. Note that to write persisted objects to a resource file, the objects must be serializable. Metropolia 2013 C# programming and .NET framework

8 Creating and Localizing Resources
You can localize your application's resources for specific cultures. This allows you to build localized (translated) versions of your applications. An application loads the appropriate localized resources based on the value of the CultureInfo.CurrentUICulture property. This value is set either explicitly in the application's code or by the common language runtime based on the locale for the current user on the local computer. For more information about how CurrentUICulture is set, see Locating and Using Resources for a Specific Culture and Using the CurrentUICulture Property. Metropolia 2013 C# programming and .NET framework

9 CurrentUICulture vs CurrentCulture
defines what appropriate version of localized form (resource) is loaded CurrentCulture defines the kinds of formatting that will be applied to formatted data Metropolia 2013 C# programming and .NET framework

10 Metropolia 2013 C# programming and .NET framework
Satellite Assemblies You can deploy your application's resources in satellite assemblies. By definition, satellite assemblies only contain resource files. They do not contain any application code. In the satellite assembly deployment model, you create an application with one default assembly (which is the main assembly) and several satellite assemblies. You should create one satellite assembly for each culture that the application supports. Because the satellite assemblies are not part of the main assembly, you can easily replace or update resources corresponding to a specific culture without replacing the application's main assembly. Metropolia 2013 C# programming and .NET framework

11 Visual Studio as Localizer
The advantage of Visual Studio is that you can use it to both develop and localize an application. To localize a form, after development is complete, set the form's LocalizableAttribute (the Localizable property in the Properties Editor) to true and change its Language property to the desired target culture. Then, edit strings and adjust the location and size of controls to accommodate the strings for the target culture. When you save the localized .resx file, Visual Studio writes only the localizable properties (properties that changed in the target culture) to the file. Visual Studio automatically creates a satellite assembly for the localized .resx file in the correct directory location. Metropolia 2013 C# programming and .NET framework

12 Metropolia 2013 C# programming and .NET framework
Language property Metropolia 2013 C# programming and .NET framework

13 Loclizable User Interface Elements
There are two ways to generate resource files using the Visual Studio development environment: Have the project system generate the resource files for localizable UI elements such as text and images on the form. The resource files are then built into satellite assemblies. These are known as forms-based resources. Add a resource file template and then edit the template with the XML Designer. A reason for doing the latter is to make localizable strings that appear in dialog boxes and error messages. You must then write code to access these resources. These are known as project resources. In general, you should use forms-based resources for all resources specific to a form in your Windows Forms application. You should use project resources for all non-forms-based user interface strings and images, such as error messages. Metropolia 2013 C# programming and .NET framework


Download ppt "Metropolia 2013 C# programming and .NET framework"

Similar presentations


Ads by Google