Partilhar via


Globalização para WPF

This topic introduces issues that you should be aware of when writing Windows Presentation Foundation (WPF) applications for the global market. The globalization programming elements are defined in Microsoft .NET in System.Globalization.

Este tópico contém as seguintes seções.

  • XAML Globalization
  • Designing an International User Interface with XAML
  • Developing Localizable Applications
  • Using ClickOnce with Localized Applications
  • Tópicos relacionados

XAML Globalization

Extensible Application Markup Language (XAML) is based on XML and takes advantage of the globalization support defined in the XML specification. The following sections describe some XAML features that you should be aware of.

Character References

A character reference gives the number of the particular Unicode character it represents, in either decimal or hexadecimal. The following example shows a decimal character reference.

Ϩ

This example shows a hexadecimal character reference. Notice that it has an x in front of the hexadecimal number.

Ϩ

Codificação

A codificação suportada pelo XAML são ASCII, Unicode UTF-16 e UTF-8. A instrução de codificação é no início de XAML de documento. Se nenhum atributo encoding existe e se há uma ordem de byte, o analisador padrão UTF-8. UTF-8 e UTF-16 são as codificações preferenciais. UTF-7 is not supported. The following example demonstrates how to specify a UTF-8 encoding in a XAML file.

?xml encoding="UTF-8"?

Language Attribute

XAML uses xml:lang to represent the language attribute of an element. Para aproveitar a CultureInfo classe, o valor do atributo de idioma precisa ser um dos nomes de cultura predefinidos pelo CultureInfo. XML: lang é hereditária na árvore de elemento (por regras do XML, não necessariamente devido à herança de propriedade de dependência) e seu valor padrão é uma seqüência vazia se não for atribuído explicitamente.

The language attribute is very useful for specifying dialects. For example, French has different spelling, vocabulary, and pronunciation in France, Quebec, Belgium, and Switzerland. Also Chinese, Japanese, and Korean share code points in Unicode, but the ideographic shapes are different and they use totally different fonts.

The following Extensible Application Markup Language (XAML) example uses the fr-CA language attribute to specify Canadian French.

<TextBlock xml:lang="fr-CA">Découvrir la France</TextBlock>

Unicode

XAML supports all Unicode features including surrogates. As long as the character set can be mapped to Unicode, it is supported. For example, GB18030 introduces some characters that are mapped to the Chinese, Japanese, and Korean (CFK) extension A and B and surrogate pairs, therefore it is fully supported. A WPF application can use StringInfo to manipulate strings without understanding whether they have surrogate pairs or combining characters.

Designing an International User Interface with XAML

This section describes user interface (UI) features that you should consider when writing an application.

International Text

WPF includes built-in processing for all Microsoft .NET Framework supported writing systems.

The following scripts are currently supported:

  • Arabic

  • Bengali

  • Devanagari

  • Cyrillic

  • Greek

  • Gujarati

  • Gurmukhi

  • Hebrew

  • Ideographic scripts

  • Kannada

  • Lao

  • Latin

  • Malayalam

  • Mongolian

  • Oriya

  • Syriac

  • Tamil

  • Telugu

  • Thaana

  • Thai*

  • Tibetan

*In this release the display and editing of Thai text is supported; word breaking is not.

The following scripts are not currently supported:

  • Khmer

  • Korean Old Hangul

  • Myanmar

  • Sinhala

O sistema de escrita mecanismos de suporte OpenType fontes. OpenTypeas fontes podem incluir o OpenType tabelas de layout permitem que os criadores de fontes projetar melhor internacionais e high-end tipográficas fontes. The OpenType font layout tables contain information about glyph substitutions, glyph positioning, justification, and baseline positioning, enabling text-processing applications to improve text layout.

OpenType fonts allow the handling of large glyph sets using Unicode encoding. Such encoding enables broad international support as well as for typographic glyph variants.

WPF text rendering is powered by Microsoft ClearType sub-pixel technology that supports resolution independence. This significantly improves legibility and provides the ability to support high quality magazine style documents for all scripts.

International Layout

WPF provides a very convenient way to support horizontal, bidirectional, and vertical layouts. In presentation framework the FlowDirection property can be used to define layout. The flow direction patterns are:

  • LeftToRight - horizontal layout for Latin, East Asian and so forth.

  • RightToLeft - bidirectional for Arabic, Hebrew and so forth.

Developing Localizable Applications

When you write an application for global consumption you should keep in mind that the application must be localizable. The following topics point out things to consider.

Multilingual User Interface

Multilingual User Interfaces (MUI) is a Microsoft support for switching UIs from one language to another. A WPF application uses the assembly model to support MUI. One application contains language-neutral assemblies as well as language-dependent satellite resource assemblies. O ponto de entrada é gerenciada.EXE no assembly principal. WPFcarregador de recursos aproveita o Frameworkdo Gerenciador de recursos para pesquisa de recursos de suporte e retorno. Multiple language satellite assemblies work with the same main assembly. The resource assembly that is loaded depends on the CurrentUICulture of the current thread.

Localizable User Interface

WPFos aplicativos usam XAML para definir suas UI. XAMLpermite que os desenvolvedores especifiquem uma hierarquia de objetos com um conjunto de propriedades e lógica. The primary use of XAML is to develop WPF applications but it can be used to specify a hierarchy of any common language runtime (CLR) objects. Most developers use XAML to specify their application's UI and use a programming language such as C# to react to user interaction.

From a resource point of view, a XAML file designed to describe a language-dependent UI is a resource element and therefore its final distribution format must be localizable to support international languages. Because XAML cannot handle events many XAML applications contain blocks of code to do this. For more information, see Visão geral do XAML (WPF). O código é extraído e compilado em binários diferentes quando uma XAML arquivo é indexado para o formulário BAML do XAML. O formulário BAML de arquivos XAML, imagens e outros tipos de recurso gerenciado objetos incorporados no assembly principal ou do conjunto de recursos de satélite, que pode estar localizado em outros idiomas, quando a localização não é necessária.

Observação

WPF applications support all the Framework CLR resources including string tables, images, and so forth.

Building Localizable Applications

Localization means to adapt a UI to different cultures. To make a WPF application localizable, developers need to build all the localizable resources into a resource assembly. The resource assembly is localized into different languages, and the code-behind uses resource management API to load. One of the files required for a WPF application is a project file (.proj). All resources that you use in your application should be included in the project file. The following example from a .csproj file shows how to do this.

<Resource Include="data\picture1.jpg"/>
<EmbeddedResource Include="data\stringtable.en-US.restext"/>

To use a resource in your application instantiate a ResourceManager and load the resource you want to use. The following example demonstrates how to do this.

        Private Sub OnClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
          Dim rm As New ResourceManager("stringtable", System.Reflection.Assembly.GetExecutingAssembly())
          Text1.Text = rm.GetString("Message")
        End Sub
void OnClick(object sender, RoutedEventArgs e)
{
  ResourceManager rm = new ResourceManager ("MySampleApp.data.stringtable",
       Assembly.GetExecutingAssembly());
  Text1.Text = rm.GetString("Message");
}

Using ClickOnce with Localized Applications

ClickOnce is a new Windows Forms deployment technology that will ship with Microsoft Visual Studio 2005. It enables application installation and upgrading of Web applications. When an application that was deployed with ClickOnce is localized it can only be viewed on the localized culture. For example, if a deployed application is localized to Japanese it can only be viewed on Japanese Microsoft Windows not on English Windows. This presents a problem because it is a common scenario for Japanese users to run an English version of Windows.

The solution to this problem is setting the neutral language fallback attribute. An application developer can optionally remove resources from the main assembly and specify that the resources can be found in a satellite assembly corresponding to a specific culture. To control this process use the NeutralResourcesLanguageAttribute. O construtor da NeutralResourcesLanguageAttribute classe tem duas assinaturas, o que leva um UltimateResourceFallbackLocation parâmetro para especificar o local onde o ResourceManager deve extrair os recursos de fallback: o assembly principal ou um assembly satélite. The following example shows how to use the attribute. For the ultimate fallback location, the code causes the ResourceManager to look for the resources in the "de" subdirectory of the directory of the currently executing assembly.

[assembly: NeutralResourcesLanguageAttribute(
    "de" , UltimateResourceFallbackLocation.Satellite)]

Consulte também

Conceitos

Visão geral de globalização e localização do WPF