Compartir a través de


Quick Custom Culture to Change Euro Currency Symbol

I was asked for a quick sample of how to build a culture, so here it is: 

1.) Start an elevated command prompt (have to be elevated to run CultureAndRegionInfoBuilder.Register())  (press windows key, type cmd, press ctrl+shift+enter is one way).

2.) copy the code below to testcc.cs.  (notepad testcc.cs and cut & paste the code).

3.) in cmd, add .net to your path:  path=%path%;%windir%Microsoft.NETFrameworkv4.0.30319  (Please use Microsoft.Net Framework v4 (or whatever's later if you read this in the future), it has more fields)

4.) csc /r:sysglobl.dll "testcc.cs"

5.) testcc.exe

 

You'll have to restart any managed process using the symbol, but intl.cpl should show you the updated results.

 

This makes an et-EE.nls file in %windir%globalization, and a registry entry.  See https://blogs.msdn.com/b/shawnste/archive/2009/05/14/cheating-to-uninstall-custom-cultures-locales.aspx for how it might be pushed with an admin logon script.  You can remove the "Register" statement, recompile & rerun to remove it.

Remember all the "AS-IS, no warranty, I didn't bother to test it" stuff that's in the Terms of Use :)

-Shawn

// testcc.cs

using System;
using System.Globalization;

class Test
{
    static void Main()
    {
        // Show what we were
        Console.WriteLine("Old Currency Symbol: " + new CultureInfo("et-EE").NumberFormat.CurrencySymbol);
        Console.WriteLine("Old Currency Name: " + new RegionInfo("et-EE").CurrencyEnglishName);

        // Build new one
        CultureAndRegionInfoBuilder updated = new CultureAndRegionInfoBuilder("et-EE", CultureAndRegionModifiers.Replacement);
        updated.CurrencyEnglishName = "Euro";
        updated.CurrencyNativeName = "Euro";
        updated.ISOCurrencySymbol = "EUR";
        NumberFormatInfo format = updated.NumberFormat;
        format.CurrencySymbol = "€";
        updated.NumberFormat = format;

        // Get rid of anything there used to be
        try
        {
            // See if there's an old one to obliterate
            CultureAndRegionInfoBuilder.Unregister("et-EE");
        }
        catch
        {
            // Should worry about errors, I'm just assuming not registered.
        }

        // Register it
        updated.Register();

        // Have to re-run to show the new values
    }
}

Comments

  • Anonymous
    August 10, 2010
    The comment has been removed
  • Anonymous
    December 09, 2010
    The comment has been removed
  • Anonymous
    December 31, 2010
    The comment has been removed
  • Anonymous
    October 29, 2013
    this is not working on windows server 2008. Even after restarting the system... Please help...