WPF Multilingual Solutions - Multilingual App Toolkit

Original: WPF Multilingual Solutions - Multilingual App Toolkit

1. First install the Multilingual App Toolkit
 
2. Create a new project, click "Tools" -> "Multilingual App Toolkit" -> "Enable Selected Content" in VS
 
 

If the above issue appears, open the project AssemblyInfo.cs file, add the following code snippet, and then repeat Step 2.
 
[assembly: NeutralResourcesLanguage("en-US")]
 
3. Create a new resource file, add resources, and then modify the access modifier to Public.
 

4. Add translation language
 
Right-click the project and select the menu item shown below to add "Translation Language"
 
 
Then select the language that the app needs to support
 
 
As shown below, Chinese support has been successfully added.
 
 
5. If a new item is added or other modifications are made in the resource file .resx, the project needs to be compiled, then select all the xls files in the project, right-click "Generate Machine Translation".
 
 
As shown below, it is being translated.
 
 
6. After the translation is completed, you can find the resource file of the corresponding language under the original Login.resx.
 
 
Open the corresponding resource file. If the translation is not successful, recompile the project.
 
 
The resource file is then translated.
 
7. But the machine translation is not very complete. If you need to modify it manually, you only need to modify the corresponding xlf file (not the generated .resx file, remember) and recompile. If I want to change the "login" shown in the picture above to "login", how can I do it?
 
Double-click the "zh-Hans.xlf" file in the project to open the file for editing
 
 
Then directly modify the part to be modified, and click the Save button after the modification is completed.
 
 
Recompile the project and find that the resource file has been modified
 
 
8. Reference resources in the project
 
<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:accountResource="clr-namespace:WpfApplication2.Resource.Account"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button Content="{x:Static accountResource:Login.BtnLogIn}"></Button>
    </Grid>
</Window>
 
9. Set the application UI language
 
public partial class App : Application
{
    private CultureInfo cultureOverride = new CultureInfo("zh-Hans");
    public App()
    {
        Thread.CurrentThread.CurrentUICulture = cultureOverride;
        Thread.CurrentThread.CurrentCulture = cultureOverride;
    }
}
 
Then run the program, the effect is as shown in the figure
 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325177939&siteId=291194637