Partilhar via


Como: Use Resources in Localizable Applications

Localization means to adapt a UI to different cultures. To do this, text such as titles, captions, list box items and so forth have to be translated. To make translation easier the items to be translated are collected into resource files. See Como: Localizar um Aplicativo for information on how to create a resource file for localization. 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 code example shows this.

Exemplo

XAML

<Resource Include="data\picture1.jpg"/>

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

Para usar um recurso em seu aplicativo, você instancia ResourceManager e carregar o recurso que você deseja usar. The following 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");
}