Local Guy S
Local Guy S
Localization Support In
Microsoft .NET Framework
®
Guy
Guy Ron
Ron
.NET
.NET Developer
Developer Advisor
Advisor
Microsoft
Microsoft Israel
Israel
Agenda
Localizability
Resources
Localization Process
Localizing ASP.NET applications
Localizability
Readying software to be adapted
for a different culture or language
Common Issues:
Strings Built At Run-time
Do not concatenate string…
“Pages visited” + (Today, Monday…) is BAD
If you really, truly, have to, then…
Use String.Format:
“Pages visited {0}” (Today, Monday…)
However, when translated…
Páginas visitadas el %s (lunes, martes, …)
Páginas visitadas %s (hoy)
Solution: have two separate strings
Common Issues: Graphics
Use culturally-neutral images
No baseball or football image for sport
If you really want to use culture specific
images, put them in resources
Avoid using text in images
If text is included, maintain layered
source
Resources And Localization
CultureInfo
Neutral culture
Based on language
Resource only
No formatting
CurrentUICulture only
Specific culture
Based on language & region
Resource & Formatting specifics
CurrentCulture & CurrentUICulture
Resource Model
.NET Framework uses a new
resource model
ResX file format
Resources files
Satellite Resources DLLs
Naming conventions
Resource Fallback
ResX Files
Simple, (almost) human-readable XML
format
Can include arbitrary objects
Created with .NET Framework SDK
Can also be created with Visual Studio®
Resource Generation Process
.resx file
XML-based file .resx file
Describes resources
.resources file
binary compiled file .resources file
Satellite .resources.dl
l:
Embedded .resources .resources.dll file
file(s)
Naming Convention
Naming pattern conventions
.resources files:
<myproject>.<xx-XX>.resources
Satellite assemblies
<myproject>.resources.dll
Main
Main Assembly
Assembly
•Code
Code
•Neutral
Neutral resources
resources (fallback)
(fallback)
Greeting=“Bonjour”
Greeting=“Bonjour”
Farewell=“Au
Farewell=“Au revoir”
revoir”
Logo=<graphic
Logo=<graphic data>
data>
English
English (en)
(en)
•No
No code
code
•““en”
en” resources
resources
Greeting
Greeting =
= “Hello”
“Hello”
Farewell
Farewell =
= “Goodbye”
“Goodbye”
English
English US
US (en-US)
(en-US)
•No
No code
code
•““en-US”
en-US” resources
resources
Greeting=“Hi”
Greeting=“Hi”
System.Resources Namespace
ResourceManager
Provides access to culture-correct resources
at runtime
ResourceWriter
Writes resources to an output stream or file
ResourceReader
Reads resources name-value pairs from
resources files and streams
ResourceSet
Stores all resources localized for
a particular culture
Loading Resources
Creating a Resource Manager
The RM constructor indicates the file from which
resources are to be loaded.
Several alternatives
Load from a loose .resources file
Load from this assembly
Load from another assembly
Load from a custom resource format if you write your
own resource manager (e.g., a database)