a localization problem !

a localization problem !

Old forum URL: forums.lhotka.net/forums/t/3659.aspx


rexhxiao posted on Sunday, October 07, 2007

i come from taiwan

use csla.net 3.0.2.0

i have code like this:

    ValidationRules.AddRule(
              Csla.Validation.CommonRules.StringRequired,
              new Csla.Validation.RuleArgs("CaseType", "案件類別"));

it is work show message => "案件類別 required"

follow Resources.zh-TW.resx

i hope it is show => "案件類別 不可空白"

my OS is chinese trandtional version

so..how to do it?

i trace csla source code find it

        internal static string StringRequiredRule
        {
            get
            {
                return ResourceManager.GetString("StringRequiredRule", resourceCulture);
            }
        }

try replace

    return ResourceManager.GetString("StringRequiredRule", resourceCulture);
to

    return ResourceManager.GetString("StringRequiredRule" + resourceCulture.DisplayName, resourceCulture);

the
 private static global::System.Globalization.CultureInfo resourceCulture;

got a null exception..

why?,i don't know ?

My poor English, hoping that someone will see to understand, about my question

RockfordLhotka replied on Sunday, October 07, 2007

My guess is that you need to have a resource.zh.resx file.

In other words, your OS is not set to use Tiawanese, but to use Traditional Chinese. So .NET looks for the traditional Chinese resource file, and perhaps there isn't one?

I don't know what the code is for traditional Chinese. Is it zh or zh-CHS?

You need to have a resource file with an exact match on the culture code OR a resource file that is more general (like resource.zh.resx).

So maybe you can try renaming .zh-TW to just .zh and see if that helps.

The final default is English, because that is what is in resource.resx.

rexhxiao replied on Sunday, October 07, 2007

Really thank you to respond to my questions
 
First, resource.zh - TW.resx is from 「cslacs - 3.0.2 - 070928 」
I think this is not a problem
Because if I replace
----------------------------------------------
    Return ResourceManager.GetString ( "StringRequiredRule" resourceCulture);
----------------------------------------------
Changed
----------------------------------------------
    Return ResourceManager.GetString ( "StringRequiredRule" System.Globalization.CultureInfo.CurrentCulture);
----------------------------------------------
That is right, that is, I want
==> "案件類別 不可空白"  (in english,mean is 「CaseType required」)
Therefore, resource.zh - TW.resx is no problem

My question is, why is null resourceCulture
 
ps.In Taiwan,xp OS version is Traditional Chinese,the CultureInfo name is 「zh-TW」.
 
Once again thanks

foxhard replied on Tuesday, November 30, 2010

Hi,

I have the same problem...

But , is changing the CSLA source code the unique way to apply localization in the validation rule messages?

I guess must there be another solution...

I have added csla.dll (Not the source code of CSLA only the assembly) as reference in my project. And I have in my project WinApp  \Properties\Resources.no.resx. And inside this file I have 

Name                                      Value

StringRequiredRule             er påkrevd

 

But when I ran my application the text continue in english: "Fieldxxx required.

What happens? the text "requires" should be "er påkrevd"

 

I hope you can help me.

Cristhiam

 

 

 

 

 

RockfordLhotka replied on Tuesday, November 30, 2010

The rules implemented in CommonRules rely on resource files for localization. If you don't like the text you get as a result there are two options.

First, if the localization for your language is wrong, or doesn't exist, please email me an updated resx file for your language. Obviously "wrong" can't be specific to your application, but must be "wrong for your entire language".

Second, if your application requires some specific text other than what's in the CommonRules implementation (in other words, the CommonRules language is "correct" but just doesn't work for you), then you should create your own rule implementation.

At no point should you feel the need to change the CommonRules implementation itself. The whole idea behind the CSLA rules subsystem is that you can create your own rules if you need them.

JonnyBee replied on Wednesday, December 01, 2010

First , please check that the resource file is complete with all keys translated from the main resource file.

ResEx is an excellent tool for this: http://resex.codeplex.com/

If the resource file is wrong or needs updating please submit to Rocky as described above.  

Which resource file is used when retrieving text is depending on the CultureInfo on current thread. For a Windows forms application you could force en-US culture using these lines in startup:

using System.Globalization;
using System.Threading;
...
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

ksavoie replied on Friday, April 08, 2011

Hi

I'm looking into using the Localization in my custom Validation rules.  I left the following question under a different discusion without any answer, I'm hoping you can help me.

I've created my custom Validation rules ok and they work fine.  I using windows form (vb.net 2005 with CSLA 2.0), and my users have the option to change the language of the application.  With this I need to be able to show the error message in the different language.  I can change my CultureInfo no problem, my problem is...

I've used the following code to access the resources files:

 Dim mRS As New ResourceManager("frmMain", System.Reflection.Assembly.Load("frmMain"))

And in my custom rule this is the code I'm using:

e.Description = mRS.GetString("Invoice_Name")

When I do this, I get a Fetch failed (DataPortal.Fetch failed, Message: "Exception has been thrown by the target of an invocation.").  I've tried a few things, and when I thought I had the right code, I was getting a Serialization exception on the save.

So do you think it would be possible to get an example on localization inside the object itself to help me out?

Thanks

K

Copyright (c) Marimer LLC