Presentation is loading. Please wait.

Presentation is loading. Please wait.

7/23/2016 CSC 325 Advanced Programming Techniques Localization Slide #1 1 Localization Mikhail Brikman.

Similar presentations


Presentation on theme: "7/23/2016 CSC 325 Advanced Programming Techniques Localization Slide #1 1 Localization Mikhail Brikman."— Presentation transcript:

1 7/23/2016 CSC 325 Advanced Programming Techniques Localization Slide #1 1 Localization Mikhail Brikman

2 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #2 2 Chapter 28 Topics Discussed Classes representing cultures/regions. Localization resources. Globalization.

3 Application Internationalization Internationalization == i18n. System.Globalization namespace represents culture related information (language, country/region, calendars in use, format patterns for dates, currency, and numbers, and sort order for strings).System.Globalization An application can be localized easier if the executable code has been separated from the localizable resources – one per each locale supported. CLR uses satellite assembly resource model to support separation of code and resources.resource model Executable code is in the main assembly and resources are in the resource files compiled into separate DLLs. 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #3 3

4 Unicode Character encoding.Character encoding Unicode Consortium.Unicode Consortium.NET is based on Unicode UTF-16. System.Text namespace represents ASCII, ANSI, Unicode, and other character encodings.System.Text 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #4 4

5 Cultures and Regions - I CultureInfo class specifies a unique name for each culture, as a combination of an ISO 639 two-letter lowercase culture code associated with a language and an ISO 3166 two-letter uppercase subculture code associated with a country or region, e.g. ja-JP for Japanese (Japan) and en-US for English (United States).CultureInfoISO 639ISO 3166 Neutral culture is specified by only the two-letter lowercase language code, e.g. "fr" for French and "de" for German. Invariant culture is culture insensitive and is set by name represented by an empty string (""). 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #5 5

6 Cultures and Regions - II To save culture specific data use an invariant culture, a binary format, or a specific culture independent format. National Language Support API Reference.National Language Support CultureInfo.CurrentCulture property returns a get/set property Thread.CurrentCulture – the culture used by the current thread.CultureInfo.CurrentCultureThread.CurrentCulture CultureInfo.CurrentUICulture property returns a get/set property Thread.CurrentUICulture – the culture used by the Resource Manager to invoke culture specific resources at run-time.CultureInfo.CurrentUICultureThread.CurrentUICulture 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #6 6

7 Cultures and Regions - III Number/date localization: chapter28\LocalizationDemos.sln -> NumberAndDateFormatting.csproj chapter28\LocalizationDemos.sln -> CultureDemo.csproj – uses NLS locale identifiers CultureInfo.Parent.LCID from National Language Support.National Language Support String sorting is culture dependent: chapter28\LocalizationDemos.sln -> SortingDemo.csproj 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #7 7

8 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #8 8 Embedding Resources - I chapter28\Resources\Wrox.ProCSharp.Localization.MyResources.txt Resources describe data logically deployed with an application: error messages, text, images, and persisted objects. Stored in resource files so that the data can be modified without recompiling the application. System.Resources.ResourceManager class provides access to culture specific resources at run time.System.Resources.ResourceManager

9 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #9 9 Embedding Resources - II Resource file generator Resgen.exe is a command- line utility that converts text (.txt or.restext) files and XML-based resource format (.resx) files to common language runtime binary (.resources) files that can be embedded in a runtime binary executable or compiled into satellite assemblies.Resgen.exe ResXResourceWriter class writes resources in XML format.ResXResourceWriter ResourceWriter class creates binary resource files.ResourceWriter

10 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #10 10 Embedding Resources - III chapter28\LocalizationDemos.sln -> CreateResource.csproj Generates chapter28\CreateResource\bin\Debug\Demo.resx – open to view in Visual Studio. Resource handling options.Resource handling options

11 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #11 11 Embedding Resources - IV VS 2015 provides resource creation options listed below. Creating Resource Files:Creating Resource Files  Manually create a text file with string resources.  Manually create an XML resource (.resx) file with string, image, or object data.  Programmatically create an XML resource (.resx) file using System.Resources namespace. Programmatically System.Resources  Programmatically create a binary resource (.resources) file.  Use Visual Studio resource editor to create a resource file and to include it in the project.

12 Embedding Resources - V Resource access at run-time: 1.Strongly typed resource is a compile-time feature that encapsulates access to resources by creating classes that contain a set of static read-only (get) properties. Open resource file (create using Resources tab in the VS Properties window if the file does not exist) in Visual Studio and set “Access Modifier” to public or internal.Strongly typed resource 2.Using the GetString and GetObject methods of the ResourceManager class.GetStringGetObject ResourceManager chapter28\LocalizationDemos.sln -> ResourceDemo.csproj, Demo.resx, Demo.Designer.cs 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #12 12

13 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #13 13 Code Localization Assembly resource files *.resx. Edit in Visual Studio. Each resource is named with a unique string identifier. Supports localization == resource is dependent on the culture. chapter28\LocalizationDemos.sln -> BookOfTheDay.csproj, Properties -> Resources Command line arguments in Visual Studio: Solution Explorer -> Project Name -> Properties -> Debug tab -> Command line arguments.

14 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #14 14 Satellite Assemblies - I.NET uses hub and spoke model to package and deploy resources.hub and spoke Hub is the main assembly that contains the non- localizable executable code and the resources for a single (neutral or default) culture. Default culture == fallback culture for the application. Each spoke connects to a satellite assembly (DLL) that contains the resources for a single culture, but does not contain any executable code.

15 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #15 15 Satellite Assemblies - II Contain only resources. New resources can be added dynamically after deployment. To add a resource in VS: "Solution Explorer" → Right-click the project name → "Add" → "New Item" → “Visual C# Items” → "Resources File". Only assemblies for the current culture are loaded into memory at the startup. Each resource must have the same unique string identifier in all cultures.

16 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #16 16 Satellite Assemblies - III Resource files naming conventions: 1.filename.resx 2.filename..resx 3.filename. -.resx The first file in the list is the default resource file so if the application does not have a localized version of a particular language and culture the default resource file will be used. Subsequent items are resource files for specific language. Example: Forms.resx, Forms.en-GB.resx, Forms.pl.resx, Forms.de-DE.resx

17 7/23/2016 CS 325 Advanced Programming Techniques Localization Slide #17 17 Satellite Assemblies - IV Visual Studio automatically creates satellite assemblies for all cultures: chapter28\BookOfTheDay\bin\Debug\de chapter28\BookOfTheDay\bin\Debug\fr If the code does not specifically request a culture, the current culture is used by default == fallback.


Download ppt "7/23/2016 CSC 325 Advanced Programming Techniques Localization Slide #1 1 Localization Mikhail Brikman."

Similar presentations


Ads by Google