2017-09-13 30 views
0

我正在開發一個aspnetboilerplate Angular 4項目,我想替換RTL語言的css文件。aspnetboilerplate用於RTL語言的角度Cli開關css

如果由於Angular Cli生成靜態頁面而無法實現,請告訴我如何根據當前的語言爲RTL語言選擇不同的index.html文件(假設爲index-ar.html)在下面的代碼:

 app.Use(async (context, next) => 
     { 
      await next(); 
      if (context.Response.StatusCode == 404 
       && !Path.HasExtension(context.Request.Path.Value)) 
      { 
       context.Request.Path = "/index.html"; 
       await next(); 
      } 
     }); 

在上面的代碼,它總是選擇index.html的,所以我要檢查當前的語言和希望的路徑設置爲「索引rtl.html」。

回答

0

我可以通過使用下面的代碼來解決這個問題:

  if (context.Response.StatusCode == 404 
       && !Path.HasExtension(context.Request.Path.Value)) 
      { 
       string culture = "en"; 
       if (context.Request.Cookies.ContainsKey("Abp.Localization.CultureName")) 
       { 
        culture = context.Request.Cookies["Abp.Localization.CultureName"]; 
       } 

       if (context.Request.Path.Value == "app/ar" || culture=="ar") 
        context.Request.Path = "/ar/index.html"; 
       else 
        context.Request.Path = "/index.html"; 
       await next(); 
      } 

我有兩個索引文件,對於英語,我在wwwwroot文件夾中的文件,而阿拉伯語index.html文件,在wwwwroot \ ar文件夾中。在Angular層面上,我將路徑設置爲「app/ar」到我的家庭組件,並且此解決方案運行良好。