Update a built-in culture with CultureAndRegionInfoBuilder?

E

Eric G

I'm attempting to change the built in .Net culture fr-CA, using the following
method:

//// Code
CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder("fr-CA",
CultureAndRegionModifiers.Replacement);

cib.NumberFormat.CurrencyGroupSeparator = ",";
cib.NumberFormat.CurrencyDecimalSeparator = ".";
cib.NumberFormat.NumberGroupSeparator = ",";
cib.NumberFormat.NumberDecimalSeparator = ".";

cib.Register();
///////

However, the Register() call fails with "System.InvalidOperationException:
The 'Register' method failed because the custom culture 'fr-CA' already
exists."

Is it possible to update the built-in culture? According to the docs
(http://msdn.microsoft.com/en-us/lib...ninfobuilder.cultureandregioninfobuilder.aspx),
it looks like I can just update it, though I might be reading that wrong.

This is running on .Net 3.5 on Server 2008 -- process is running with
adminstrative privledges.
 
J

Jie Wang [MSFT]

Hi,

The CultureAndRegionInfoBuilder class is used to define a custom culture
that is new or based on another culture and country/region.

The fr-CA is an already known culture so you don't have to register it.

One thing I don't quite get it is - when you say "attempting to change the
built in .Net culture", what exactly do you mean by "built in" here?

Could you please explain what do you want to do with more details so I can
give more specific suggestions?

Anyway, if you mean the running application's default culture, then you can
set it via the Thread.CurrentCulture & Thread.CurrentUICulture properties:

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

The CurrentUICulture affects how Resource Manager looks up culture-specific
resources at runtime.
The CurrentCulture affects the culture-specific behavior of methods like
String.Format or Compare.

References:
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuicul
ture.aspx
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentcultu
re.aspx

Please let me know if you have any further questions.

Best regards,

Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
E

Eric G

By "built-in", I mean pre-exisiting culture. So, is it possible to change
the exisiting culture fr-CA?

We unfortunatly have some hard coded usage of "fr-CA", but would like to
change the currency/number formats (from 123 456,00 to 123,456.00), without
creating a custom culture.

Is it possible to do that?

"Jie Wang [MSFT]" said:
Hi,

The CultureAndRegionInfoBuilder class is used to define a custom culture
that is new or based on another culture and country/region.

The fr-CA is an already known culture so you don't have to register it.

One thing I don't quite get it is - when you say "attempting to change the
built in .Net culture", what exactly do you mean by "built in" here?

Could you please explain what do you want to do with more details so I can
give more specific suggestions?

Anyway, if you mean the running application's default culture, then you can
set it via the Thread.CurrentCulture & Thread.CurrentUICulture properties:

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

The CurrentUICulture affects how Resource Manager looks up culture-specific
resources at runtime.
The CurrentCulture affects the culture-specific behavior of methods like
String.Format or Compare.

References:
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuicul
ture.aspx
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentcultu
re.aspx

Please let me know if you have any further questions.

Best regards,

Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
E

Eric G

more info -- this is basically what I'm trying to do (they are using en-GB,
but it is the same case as mine):

"The CultureAndRegionInfoBuilder constructor accepts two parameters: the
custom culture name and an enumeration identifying what kind of custom
culture the new culture is. The replacement culture is registered using the
Register method. Once registered, all .NET Framework 2.0 applications on this
machine will use the modified en-GB culture instead of the original, without
any change to those applications."

http://en.csharp-online.net/Using_Custom_Cultures—Using_CultureAndRegionInfoBuilder



Eric G said:
By "built-in", I mean pre-exisiting culture. So, is it possible to change
the exisiting culture fr-CA?

We unfortunatly have some hard coded usage of "fr-CA", but would like to
change the currency/number formats (from 123 456,00 to 123,456.00), without
creating a custom culture.

Is it possible to do that?

"Jie Wang [MSFT]" said:
Hi,

The CultureAndRegionInfoBuilder class is used to define a custom culture
that is new or based on another culture and country/region.

The fr-CA is an already known culture so you don't have to register it.

One thing I don't quite get it is - when you say "attempting to change the
built in .Net culture", what exactly do you mean by "built in" here?

Could you please explain what do you want to do with more details so I can
give more specific suggestions?

Anyway, if you mean the running application's default culture, then you can
set it via the Thread.CurrentCulture & Thread.CurrentUICulture properties:

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

The CurrentUICulture affects how Resource Manager looks up culture-specific
resources at runtime.
The CurrentCulture affects the culture-specific behavior of methods like
String.Format or Compare.

References:
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuicul
ture.aspx
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentcultu
re.aspx

Please let me know if you have any further questions.

Best regards,

Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jie Wang [MSFT]

Hi,

Thanks for the clarification. Now I know why you're getting this
InvalidOperationException.

When you call cib.Register the first time, if it succeeded, your custom
culture information is already persisted in the %WINDIR%\Globalization
folder as a file. The following call of the Register method trying to
register the same custom culture will fail because the file already exists.

The solution to this problem depends on your application logic.

Option 1: You can either choose to ignore the InvalidOperationException if
the custom culture already exists, but this does not guarantee the existing
custom culture has the same setting as you wanted.

Option 2: Or you can call CultureAndRegionInfoBuilder.Unregister("fr-CA");
before start registering your custom culture, and ignore errors if there is
not already such a custom culture to unregister.

Option 3: Another safer way is to first check current settings of fr-CA, if
it does not meet your settings, then do option 2.

Here is the sample code:

CultureInfo ci = new CultureInfo("fr-CA");

// first check if the settings are match
if (ci.NumberFormat.CurrencyGroupSeparator != "," ||
ci.NumberFormat.CurrencyDecimalSeparator != "." ||
ci.NumberFormat.NumberGroupSeparator != "," ||
ci.NumberFormat.NumberDecimalSeparator != ".")
{
try
{
// if not match, try delete existing custom culture.
CultureAndRegionInfoBuilder.Unregister("fr-CA");
}
catch
{
// ignore or process exception, your call
}

// start register the custom culture
CultureAndRegionInfoBuilder cib = new
CultureAndRegionInfoBuilder("fr-CA", CultureAndRegionModifiers.Replacement);

cib.NumberFormat.CurrencyGroupSeparator = ",";
cib.NumberFormat.CurrencyDecimalSeparator = ".";
cib.NumberFormat.NumberGroupSeparator = ",";
cib.NumberFormat.NumberDecimalSeparator = ".";

cib.Register();
}

// test the custom culture.
Console.WriteLine(String.Format(new CultureInfo("fr-CA"), "{0:C}",
10000.1231F));


If you have any further questions, please kindly let me know.

Thanks,

Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
E

Eric G

Using Unregister() worked perfectly, thanks.

"Jie Wang [MSFT]" said:
Hi,

Thanks for the clarification. Now I know why you're getting this
InvalidOperationException.

When you call cib.Register the first time, if it succeeded, your custom
culture information is already persisted in the %WINDIR%\Globalization
folder as a file. The following call of the Register method trying to
register the same custom culture will fail because the file already exists.

The solution to this problem depends on your application logic.

Option 1: You can either choose to ignore the InvalidOperationException if
the custom culture already exists, but this does not guarantee the existing
custom culture has the same setting as you wanted.

Option 2: Or you can call CultureAndRegionInfoBuilder.Unregister("fr-CA");
before start registering your custom culture, and ignore errors if there is
not already such a custom culture to unregister.

Option 3: Another safer way is to first check current settings of fr-CA, if
it does not meet your settings, then do option 2.

Here is the sample code:

CultureInfo ci = new CultureInfo("fr-CA");

// first check if the settings are match
if (ci.NumberFormat.CurrencyGroupSeparator != "," ||
ci.NumberFormat.CurrencyDecimalSeparator != "." ||
ci.NumberFormat.NumberGroupSeparator != "," ||
ci.NumberFormat.NumberDecimalSeparator != ".")
{
try
{
// if not match, try delete existing custom culture.
CultureAndRegionInfoBuilder.Unregister("fr-CA");
}
catch
{
// ignore or process exception, your call
}

// start register the custom culture
CultureAndRegionInfoBuilder cib = new
CultureAndRegionInfoBuilder("fr-CA", CultureAndRegionModifiers.Replacement);

cib.NumberFormat.CurrencyGroupSeparator = ",";
cib.NumberFormat.CurrencyDecimalSeparator = ".";
cib.NumberFormat.NumberGroupSeparator = ",";
cib.NumberFormat.NumberDecimalSeparator = ".";

cib.Register();
}

// test the custom culture.
Console.WriteLine(String.Format(new CultureInfo("fr-CA"), "{0:C}",
10000.1231F));


If you have any further questions, please kindly let me know.

Thanks,

Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Ariel Sartor

HUMM, I'am using net framework 3.5 and vs2008, CultureAndRegionInfoBuilder assenbly is privated of Net Framework 4 and VS 2010? Does exists the option to integrate to vs2008?, thanks




Eric G wrote:

RE: Update a built-in culture with CultureAndRegionInfoBuilder?
06-Aug-09

Using Unregister() worked perfectly, thanks

:

Previous Posts In This Thread:

Update a built-in culture with CultureAndRegionInfoBuilder?
I am attempting to change the built in .Net culture fr-CA, using the followin
method

//// Cod
CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder("fr-CA"
CultureAndRegionModifiers.Replacement)

cib.NumberFormat.CurrencyGroupSeparator = ","
cib.NumberFormat.CurrencyDecimalSeparator = "."
cib.NumberFormat.NumberGroupSeparator = ","
cib.NumberFormat.NumberDecimalSeparator = "."

cib.Register()
//////

However, the Register() call fails with "System.InvalidOperationException
The 'Register' method failed because the custom culture 'fr-CA' alread
exists.

Is it possible to update the built-in culture? According to the doc
(http://msdn.microsoft.com/en-us/lib...ninfobuilder.cultureandregioninfobuilder.aspx)
it looks like I can just update it, though I might be reading that wrong

This is running on .Net 3.5 on Server 2008 -- process is running wit
adminstrative privledges.

Hi,The CultureAndRegionInfoBuilder class is used to define a custom culture
Hi

The CultureAndRegionInfoBuilder class is used to define a custom cultur
that is new or based on another culture and country/region

The fr-CA is an already known culture so you do not have to register it

One thing I do not quite get it is - when you say "attempting to change th
built in .Net culture", what exactly do you mean by "built in" here

Could you please explain what do you want to do with more details so I ca
give more specific suggestions

Anyway, if you mean the running application's default culture, then you ca
set it via the Thread.CurrentCulture & Thread.CurrentUICulture properties

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

The CurrentUICulture affects how Resource Manager looks up culture-specifi
resources at runtime
The CurrentCulture affects the culture-specific behavior of methods lik
String.Format or Compare

References
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuicu
ture.asp
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentcult
re.asp

Please let me know if you have any further questions

Best regards

Jie Wan

Microsoft Online Community Suppor

Delighting our customers is our #1 priority. We welcome your comments an
suggestions about how we can improve the support we provide to you. Pleas
feel free to let my manager know what you think of the level of servic
provided. You can send feedback directly to my manager at
(e-mail address removed)

=================================================
Get notification to my posts through email? Please refer t
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications

Note: MSDN Managed Newsgroup support offering is for non-urgent issue
where an initial response from the community or a Microsoft Suppor
Engineer within 2 business days is acceptable. Please note that each follo
up response may take approximately 2 business days as the suppor
professional working with you may need further investigation to reach th
most efficient resolution. The offering is not appropriate for situation
that require urgent, real-time or phone-based interactions. Issues of thi
nature are best handled working with a dedicated Microsoft Support Enginee
by contacting Microsoft Customer Support Services (CSS) a
http://msdn.microsoft.com/en-us/subscriptions/aa948874.asp
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

By "built-in", I mean pre-exisiting culture.
By "built-in", I mean pre-exisiting culture. So, is it possible to change
the exisiting culture fr-CA?

We unfortunatly have some hard coded usage of "fr-CA", but would like to
change the currency/number formats (from 123 456,00 to 123,456.00), without
creating a custom culture.

Is it possible to do that?

:

more info -- this is basically what I'm trying to do (they are using en-GB,
more info -- this is basically what I am trying to do (they are using en-GB,
but it is the same case as mine):

"The CultureAndRegionInfoBuilder constructor accepts two parameters: the
custom culture name and an enumeration identifying what kind of custom
culture the new culture is. The replacement culture is registered using the
Register method. Once registered, all .NET Framework 2.0 applications on this
machine will use the modified en-GB culture instead of the original, without
any change to those applications."

http://en.csharp-online.net/Using_Custom_Cultures—Using_CultureAndRegionInfoBuilder



:

Hi,Thanks for the clarification.
Hi,

Thanks for the clarification. Now I know why you are getting this
InvalidOperationException.

When you call cib.Register the first time, if it succeeded, your custom
culture information is already persisted in the %WINDIR%\Globalization
folder as a file. The following call of the Register method trying to
register the same custom culture will fail because the file already exists.

The solution to this problem depends on your application logic.

Option 1: You can either choose to ignore the InvalidOperationException if
the custom culture already exists, but this does not guarantee the existing
custom culture has the same setting as you wanted.

Option 2: Or you can call CultureAndRegionInfoBuilder.Unregister("fr-CA");
before start registering your custom culture, and ignore errors if there is
not already such a custom culture to unregister.

Option 3: Another safer way is to first check current settings of fr-CA, if
it does not meet your settings, then do option 2.

Here is the sample code:

CultureInfo ci = new CultureInfo("fr-CA");

// first check if the settings are match
if (ci.NumberFormat.CurrencyGroupSeparator != "," ||
ci.NumberFormat.CurrencyDecimalSeparator != "." ||
ci.NumberFormat.NumberGroupSeparator != "," ||
ci.NumberFormat.NumberDecimalSeparator != ".")
{
try
{
// if not match, try delete existing custom culture.
CultureAndRegionInfoBuilder.Unregister("fr-CA");
}
catch
{
// ignore or process exception, your call
}

// start register the custom culture
CultureAndRegionInfoBuilder cib = new
CultureAndRegionInfoBuilder("fr-CA", CultureAndRegionModifiers.Replacement);

cib.NumberFormat.CurrencyGroupSeparator = ",";
cib.NumberFormat.CurrencyDecimalSeparator = ".";
cib.NumberFormat.NumberGroupSeparator = ",";
cib.NumberFormat.NumberDecimalSeparator = ".";

cib.Register();
}

// test the custom culture.
Console.WriteLine(String.Format(new CultureInfo("fr-CA"), "{0:C}",
10000.1231F));


If you have any further questions, please kindly let me know.

Thanks,

Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

RE: Update a built-in culture with CultureAndRegionInfoBuilder?
Using Unregister() worked perfectly, thanks.

:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Six Free Visual Studio 2010 MSDN Memberships Giveaway
http://www.eggheadcafe.com/tutorial...al-studio-2010-msdn-memberships-giveaway.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top