【问题标题】:Translate MessageDialog (C#)翻译 MessageDialog (C#)
【发布时间】:2017-07-26 05:15:24
【问题描述】:

我有这个 var dialog = new MessageDialog("Error", "Error: Example"); await dialog.ShowAsync(); 在 XAML 中我这样翻译:x:Uid="Example" 我想翻译您在 messagedialog 中显示的消息 如何在 C# 中进行翻译?

【问题讨论】:

    标签: c# visual-studio-2015 uwp uwp-xaml


    【解决方案1】:

    您可以使用ResourceLoader 类:

    string localizedString = ResourceLoader.GetForCurrentView().GetString("<Key from resw>");
    

    您可以将可选字符串传递给 GetForCurrentView 方法,您可以在其中指定 resw 文件的名称。

    更新

    GetString 方法返回一个字符串对象,您可以使用它来创建MessageDialog

    var loader = ResourceLoader.GetForCurrentView();
    string title = loader.GetString("example_Title"); 
    string content = loader.GetString("example_Content"); 
    var dialog = new MessageDialog(content, title);
    await dialog.ShowAsync();
    

    更新 2

    resw 文件中的键不能包含 '.'出于某种原因的性格。可能是因为 x:Uid 行为...

    【讨论】:

    • 我把这段代码放在我想翻译的 C# 中,对吗?那我怎么在 .resw 文件中做呢?
    • 是的,如果您想翻译并且您的 resw 文件看起来与您使用 x:Uid 相同,您可以在您的 C# 文件中使用它。您将 Uid 密钥传递给 GetString 方法。
    • 我在我的 C# 文件中有这个:(示例是我的 Uid)string localizedString = ResourceLoader.GetForCurrentView().GetString("example"); var dialog = new MessageDialog("", ""); 在 .resw 我有这个:example.Content 和 example.Title anda 翻译但不工作,不出现任何东西
    • 我找到了:.键中的(点)字符是坏人。
    • 我的示例代码正在运行,你能提供你的代码(C# + resw)吗?
    猜你喜欢
    • 2015-10-21
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 2017-01-25
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多