2017-09-14 2 views
1

ドイツ語のFormFlowですべての文字列と列挙体をローカライズする必要があります。私は見ているhttps://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-formflow-localize そしてそれは2つの方法があると言います。 1つはIFormBuilder.SaveResourcesを使用し、もう1つはRViewツールを使用しています(これはわかりませんでした)。 AnnotatedSandwich Botのように、ドイツ語と英語の両方の.resxファイルを生成して保存するには、最初の方法を使用できますか?私はの.resx.de.resx.en.resxファイル を生成するコードのどの部分に置く必要がありますBuildLocalizeForm()次の例FormFlowでIFormBuilder.SaveResourcesを使用してresourseファイルを作成する方法(Bot Builder C#SDK)

  • ここではそのサンプルです:https://github.com/Microsoft/BotBuilder/tree/master/CSharp/Samples/AnnotatedSandwichBot

    public static IForm<SandwichOrder> BuildLocalizedForm() 
        { 
         var culture = Thread.CurrentThread.CurrentUICulture; 
    
         IForm<SandwichOrder> form; 
         if (!_forms.TryGetValue(culture, out form)) 
         { 
          OnCompletionAsyncDelegate<SandwichOrder> processOrder = async (context, state) => 
              { 
               await context.PostAsync(DynamicSandwich.Processing); 
              }; 
          // Form builder uses the thread culture to automatically switch framework strings 
          // and also your static strings as well. Dynamically defined fields must do their own localization. 
          var builder = new FormBuilder<SandwichOrder>() 
            .Message("Welcome to the sandwich order bot!") 
            .Field(nameof(Sandwich)) 
            .Field(nameof(Length)) 
            .Field(nameof(Bread)) 
            .Field(nameof(Cheese)) 
            .Field(nameof(Toppings), 
             validate: async (state, value) => 
             { 
              var values = ((List<object>)value).OfType<ToppingOptions>(); 
              var result = new ValidateResult { IsValid = true, Value = values }; 
              if (values != null && values.Contains(ToppingOptions.Everything)) 
              { 
               result.Value = (from ToppingOptions topping in Enum.GetValues(typeof(ToppingOptions)) 
                   where topping != ToppingOptions.Everything && !values.Contains(topping) 
                   select topping).ToList(); 
              } 
              return result; 
             }) 
            .Message("For sandwich toppings you have selected {Toppings}.") 
            .Field(nameof(SandwichOrder.Sauces)) 
            .Field(new FieldReflector<SandwichOrder>(nameof(Specials)) 
             .SetType(null) 
             .SetActive((state) => state.Length == LengthOptions.FootLong) 
             .SetDefine(async (state, field) => 
              { 
               field 
                .AddDescription("cookie", DynamicSandwich.FreeCookie) 
                .AddTerms("cookie", Language.GenerateTerms(DynamicSandwich.FreeCookie, 2)) 
                .AddDescription("drink", DynamicSandwich.FreeDrink) 
                .AddTerms("drink", Language.GenerateTerms(DynamicSandwich.FreeDrink, 2)); 
               return true; 
              })) 
            .Confirm(async (state) => 
             { 
              var cost = 0.0; 
              switch (state.Length) 
              { 
               case LengthOptions.SixInch: cost = 5.0; break; 
               case LengthOptions.FootLong: cost = 6.50; break; 
              } 
              return new PromptAttribute(string.Format(DynamicSandwich.Cost, cost) + "{||}"); 
             }) 
            .Field(nameof(SandwichOrder.DeliveryAddress), 
             validate: async (state, response) => 
             { 
              var result = new ValidateResult { IsValid = true, Value = response }; 
              var address = (response as string).Trim(); 
              if (address.Length > 0 && address[0] < '0' || address[0] > '9') 
              { 
               result.Feedback = DynamicSandwich.BadAddress; 
               result.IsValid = false; 
              } 
              return result; 
             }) 
            .Field(nameof(SandwichOrder.DeliveryTime), "What time do you want your sandwich delivered? {||}") 
            .Confirm("Do you want to order your {Length} {Sandwich} on {Bread} {&Bread} with {[{Cheese} {Toppings} {Sauces}]} to be sent to {DeliveryAddress} {?at {DeliveryTime:t}}?") 
            .AddRemainingFields() 
            .Message("Thanks for ordering a sandwich!") 
            .OnCompletion(processOrder); 
          builder.Configuration.DefaultPrompt.ChoiceStyle = ChoiceStyleOptions.Auto; 
          form = builder.Build(); 
          _forms[culture] = form; 
         } 
         return form; 
        } 
    
+0

RViewの事柄はhttps://stackoverflow.com/questions/46199439/how-to-use-rview-tool-in-bot-builder-c-sdk-to-localize-strings-in-formで説明されています。流れ、それを行う方法はかなり明確です。 –

答えて

2

BEFあなたはIResourceWriterを渡すbuilder.SaveResourcesを呼び出すことができますライン

form = builder.Build(); 

鉱石。 ResourceWriterを作成する方法を理解するための

は、https://msdn.microsoft.com/en-us/library/system.resources.resourcewriter(v=vs.110).aspxを読んでいますが、基本的にのようなものになります。それでも

ResourceWriter writer = new ResourceWriter("myResources.resources"); 

を、私はあなたがRViewオプションを指定して行くべきだと考えています。手順を踏んでいないので、RviewツールをDLLと同じパスに置いたり、DLLへのフルパスを渡すRViewを呼び出したりするのと同じくらい簡単です。

関連する問題