コード例 #1
0
    public static void Main()
    {
        CultureAndRegionInfoBuilder cib = null;

        try
        {
            // Create a CultureAndRegionInfoBuilder
            // object named "ro-MD".
            cib = new CultureAndRegionInfoBuilder(
                "ro-MD", CultureAndRegionModifiers.None);
            // Populate the new CultureAndRegionInfoBuilder
            // object with culture information.
            CultureInfo ci = new CultureInfo("ro-RO");
            cib.LoadDataFromCultureInfo(ci);
            // Populate the new CultureAndRegionInfoBuilder
            // object with region information.
            RegionInfo ri = new RegionInfo("RO");
            cib.LoadDataFromRegionInfo(ri);
            var filePath = "ro-MD.xml";
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            // Save as XML
            cib.Save(filePath);
            // TODO: modify the XML
            var xDoc = XDocument.Load(filePath);
            var ns   =
                "http://schemas.microsoft.com/globalization/2004/08/carib/ldml";
            xDoc.Descendants(XName.Get("regionEnglishName", ns))
            .FirstOrDefault().Attribute("type").SetValue("Moldova");
            xDoc.Descendants(XName.Get("regionNativeName", ns))
            .FirstOrDefault().Attribute("type").SetValue("Moldova");
            // and so on
            xDoc.Save(filePath);
            var roMd = CultureAndRegionInfoBuilder
                       .CreateFromLdml(filePath);
            // this may throw an exception if the culture info exists
            try
            {
                CultureAndRegionInfoBuilder.Unregister("ro-MD");
            }
            catch (Exception)
            {
                //throw;
            }
            // Register the custom culture.
            roMd.Register();
            // Display some of the properties of the custom culture.
            var riMd = new RegionInfo("ro-MD");
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
コード例 #2
0
    //Register culture from XML file
    private void cmdCreateCultureFromXML()
    {
        if (cultureExist())
        {
            CultureAndRegionInfoBuilder.Unregister("ku-KU");
        }
        CultureAndRegionInfoBuilder cib = CultureAndRegionInfoBuilder.CreateFromLdml(@"C:\temp\kurdish.xml");

        cib.Register();
    }
コード例 #3
0
        public int Action()
        {
            var filePath = InputFile;

            if (File.Exists(filePath) == false)
            {
                filePath = Path.Combine(".", filePath);
                if (File.Exists(filePath) == false)
                {
                    Console.WriteLine($"File not found: '{InputFile}'.");
                    return(1);
                }
            }

            try
            {
                var match = _cultureRegex.Match(InputFile);
                if (match.Success)
                {
                    var cultureName = match.Groups[1].Value;

                    if (CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(x => x.Name.ToLowerInvariant() == cultureName.ToLowerInvariant()) != null)
                    {
                        Console.WriteLine($"Cannot import - culture '{cultureName}' already exists.");
                        return(1);
                    }

                    // Build and register a temporary culture with the name of what we want to import.
                    // CreateFromLdml method will fail when trying to load a culture from file if it doesn't already exist.
                    var tempCulture = new CultureAndRegionInfoBuilder(cultureName, CultureAndRegionModifiers.None);
                    tempCulture.LoadDataFromCultureInfo(CultureInfo.CurrentCulture);
                    tempCulture.LoadDataFromRegionInfo(RegionInfo.CurrentRegion);
                    tempCulture.Register();

                    // Now load up the culture we actually want to import
                    var culture = CultureAndRegionInfoBuilder.CreateFromLdml(filePath);

                    // Unregister the temporary culture
                    CultureAndRegionInfoBuilder.Unregister(cultureName);

                    // Register the real culture loaded from file
                    culture.Register();

                    Console.WriteLine($"Culture '{culture.CultureName}' has been installed.");
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }

            return(0);
        }
コード例 #4
0
ファイル: sl.cs プロジェクト: ruo2012/samples-1
    public static void Main()
    {
        string savedCARIB = "mySavedCARIB.xml";
        string msg1       = "The name of the original CultureAndRegionInfoBuilder" +
                            " is \"{0}\".";
        string msg2 = "Reconstituting the CultureAndRegionInfoBuilder object " +
                      "from \"{0}\".";
        string msg3 = "The name of the reconstituted CultureAndRegionInfoBuilder" +
                      " is \"{0}\".";

// Construct a new, privately used culture that extends the en-US culture
// provided by the .NET Framework. In this sample, the CultureAndRegion-
// Types.Specific parameter creates a minimal CultureAndRegionInfoBuilder
// object that you must populate with culture and region information.

        CultureAndRegionInfoBuilder cib1 = null;
        CultureAndRegionInfoBuilder cib2 = null;

        try {
            cib1 = new CultureAndRegionInfoBuilder(
                "x-en-US-sample", CultureAndRegionModifiers.None);
        }
        catch (ArgumentException ae)
        {
            Console.WriteLine(ae);
            return;
        }

// Populate the new CultureAndRegionInfoBuilder object with culture information.
        CultureInfo ci = new CultureInfo("en-US");

        cib1.LoadDataFromCultureInfo(ci);

// Populate the new CultureAndRegionInfoBuilder object with region information.
        RegionInfo ri = new RegionInfo("US");

        cib1.LoadDataFromRegionInfo(ri);

// Display a property of the new custom culture.
        Console.Clear();
        Console.WriteLine(msg1, cib1.CultureName);

// Save the new CultureAndRegionInfoBuilder object in the specified file in
// LDML format. The file is saved in the same directory as the application
// that calls the Save method.

        Console.WriteLine("Saving the custom culture to a file...");
        try {
            cib1.Save(savedCARIB);
        }
        catch (IOException exc)
        {
            Console.WriteLine("** I/O exception: {0}", exc.Message);
            return;
        }

// Create a new CultureAndRegionInfoBuilder object from the persisted file.
        Console.WriteLine(msg2, savedCARIB);
        try {
            cib2 = CultureAndRegionInfoBuilder.CreateFromLdml(savedCARIB);
        }
        catch (XmlException xe)
        {
            Console.WriteLine("** XML validation exception: {0}", xe.Message);
            return;
        }

// Display a property of the resonstituted custom culture.
        Console.WriteLine(msg3, cib2.CultureName);

// At this point you could call the Register method and make the reconstituted
// custom culture available to other applications. The mySavedCARIB.xml file
// remains on your computer.
    }
コード例 #5
0
ファイル: ImportFolder.cs プロジェクト: gormac/cultures
        public int Action()
        {
            var dir = new DirectoryInfo(Folder);

            if (dir.Exists == false)
            {
                Console.WriteLine($"Invalid folder: '{Folder}'.");
                return(1);
            }
            var files = dir.EnumerateFiles().Where(x => x.Extension == Extension);

            if (!files.Any())
            {
                Console.WriteLine("No culture files found in folder.");
                return(1);
            }
            Console.WriteLine($"Found {files.Count()} culture files.\n");
            var installCount = 0;
            var skipCount    = 0;

            foreach (var file in files)
            {
                try
                {
                    var filePath = file.FullName;
                    var match    = _cultureRegex.Match(filePath);
                    if (match.Success)
                    {
                        var cultureName = match.Groups[1].Value;

                        if (CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(x => x.Name.ToLowerInvariant() == cultureName.ToLowerInvariant()) != null)
                        {
                            Console.WriteLine($"Skipping '{cultureName}' - culture already exists.");
                            skipCount++;
                            continue;
                        }
                        // Build and register a temporary culture with the name of what we want to import.
                        // CreateFromLdml method will fail when trying to load a culture from file if it doesn't already exist.
                        var tempCulture = new CultureAndRegionInfoBuilder(cultureName, CultureAndRegionModifiers.None);
                        tempCulture.LoadDataFromCultureInfo(CultureInfo.CurrentCulture);
                        tempCulture.LoadDataFromRegionInfo(RegionInfo.CurrentRegion);
                        tempCulture.Register();
                        // Now load up the culture we actually want to import
                        var culture = CultureAndRegionInfoBuilder.CreateFromLdml(filePath);
                        // Unregister the temporary culture
                        CultureAndRegionInfoBuilder.Unregister(cultureName);

                        // Register the real culture loaded from file
                        culture.Register();
                        Console.WriteLine($"Culture '{culture.CultureName}' has been installed.");
                        installCount++;
                    }
                }
                catch (Exception e)
                {
                    Console.Write(e.Message);
                }
            }
            Console.WriteLine($"\nInstalled {installCount} and skipped {skipCount} culture files.");
            return(0);
        }