C#本地化-多个resx文件,但默认情况下仅工作一个

时间:2018-10-09 08:36:19

标签: c# localization cultureinfo resx

我有一个简单的控制台应用程序(.NET Framework 4.6.1),在这里我尝试通过更改cultureinfo使用多个resx文件。这是我的代码:

<cfif isDefined("remove")> //button in the cart page to remove a product
    <cflock scope="session" type="readonly" timeout="0200">
       <cfparam name="Session.cart">
       <cfloop query="#qProductSelected#"> //this is the query for getting productid from url
          <cfset sItem = structNew()> //this is my structure inside an array
          <cfset sItem.Image= Application.imageUrl&qProductSelected.ProductImage> //for getting image 
          <cfset sItem.ProductId =#ProductId#> //getting productid
          <cfset sItem.ProductImage = #Image#> //getting image
          <cfset sItem.ProductName = #ProductName#> //getting product name
          <cfset sItem.ProductDescription =#ProductDescription#> //getting productdescription
          <cfset sItem.quantity = form.qty> //storing quantity from form into the session
          <cfset structClear(sItem)> //finally i use structclear to clear the structure
        </cfloop>
   </cflock>
   <cflocation url="cart.cfm"> //redirecting to cart page itself
</cfif>

我的默认区域性是en-US。我在resx文件中有一行,键为“ Hello”。由于某些原因,使用fr-FR cultureinfo可以正常运行,但其他则具有后备价值。

项目csproj文件的相关部分:

       `static void Main( string[] args )
    {
        //default
        Console.WriteLine( Resource.Hello );

        Thread.CurrentThread.CurrentCulture = new CultureInfo( "fr-FR" );
        Thread.CurrentThread.CurrentUICulture = new CultureInfo( "fr-FR" );

        //french
        Console.WriteLine( Resource.Hello );

        Thread.CurrentThread.CurrentCulture = new CultureInfo( "hu-HU" );
        Thread.CurrentThread.CurrentUICulture = new CultureInfo( "hu-HU" );

        //hungarian
        Console.WriteLine( Resource.Hello );
        string res = Resource.ResourceManager.GetString( "Hello", CultureInfo.GetCultureInfo( "hu-HU" ) );
        Console.WriteLine( res );

        Console.ReadKey();
    }`

我将所有resx文件手动添加到了项目中的“属性”下。只有默认名称具有Designer.cs

有什么想法吗?感谢您的进步!

0 个答案:

没有答案