Sunday, September 23, 2018

Geolocation in C# and ASP.NET by IP address

Well here I am going to share simple method of geolocation by web page visitors IP address.
The method uses http://ip-api.com/  service which is free for use geolocation database and API (have a look at it it's worthed project).


   public static string GeoLocate()
        {
            string linfo = "N/A";

            try
            {
                WebRequest request = WebRequest.Create("http://ip-api.com/xml/" + Request.UserHostAddress);
                request.Credentials = CredentialCache.DefaultCredentials;
                WebResponse response = request.GetResponse();

                Stream dataStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(dataStream);

                linfo = reader.ReadToEnd();

                reader.Close();
                response.Close();

                int countryFrom = linfo.IndexOf("<country>");
                int countryTo = linfo.IndexOf("</country>");

                string Country = String.Empty;

                if (countryFrom != -1)
                {
                    Country = linfo.Substring(countryFrom, countryTo - countryFrom).TrimEnd(Environment.NewLine.ToCharArray()).Replace("<country>", String.Empty).Replace("<![CDATA[", String.Empty).Replace("]]>", String.Empty);
                }

                int cityFrom = linfo.IndexOf("<city>");
                int cityTo = linfo.IndexOf("</city>");

                string City = String.Empty;

                if (cityFrom != -1)
                {
                    City = linfo.Substring(cityFrom, cityTo - cityFrom).TrimEnd(Environment.NewLine.ToCharArray()).Replace("<city>", String.Empty).Replace("<![CDATA[", String.Empty).Replace("]]>", String.Empty);
                }

                int regionFrom = linfo.IndexOf("<regionName>");
                int regionTo = linfo.IndexOf("</regionName>");

                string Region = String.Empty;

                if (regionFrom != -1)
                {
                    Region = linfo.Substring(regionFrom, regionTo - regionFrom).TrimEnd(Environment.NewLine.ToCharArray()).Replace("<regionName>", String.Empty).Replace("<![CDATA[", String.Empty).Replace("]]>", String.Empty);
                }

                int latFrom = linfo.IndexOf("<lat>");
                int latTo = linfo.IndexOf("</lat>");

                string Latitude = String.Empty;

                if (latFrom != -1)
                {
                    Latitude = linfo.Substring(latFrom, latTo - latFrom).TrimEnd(Environment.NewLine.ToCharArray()).Replace("<lat>", String.Empty).Replace("<![CDATA[", String.Empty).Replace("]]>", String.Empty);
                }

                int longFrom = linfo.IndexOf("<lon>");
                int longTo = linfo.IndexOf("</lon>");

                string Longitude = String.Empty;

                if (longFrom != -1)
                {
                    Longitude = linfo.Substring(longFrom, longTo - longFrom).TrimEnd(Environment.NewLine.ToCharArray()).Replace("<lon>", String.Empty).Replace("<![CDATA[", String.Empty).Replace("]]>", String.Empty);
                }

                int orgFrom = linfo.IndexOf("<org>");
                int orgTo = linfo.IndexOf("</org>");

                string Organization = String.Empty;

                if (orgFrom != -1)
                {
                    Organization = linfo.Substring(orgFrom, orgTo - orgFrom).TrimEnd(Environment.NewLine.ToCharArray()).Replace("<org>", String.Empty).Replace("<![CDATA[", String.Empty).Replace("]]>", String.Empty);
                }

                linfo = "Country: " + Country  + " Region: " + Region + " City: " + City + " Organization: "  + " Latitude: " + Latitude +  " Longitude: " + Longitude;
            }
            catch { }

            return linfo;
        }

I hope it helps, anyway please let me know.

Thursday, September 20, 2018

C# / ASP.NET TinyMCE spell checker handler integration

All day I was looking for simple solution to integrate TinyMCE spell checker option (the free version of the spell checker) into a project I am currently working. Unfortunately I could not find any alternative for the server side of the spell checker with permissive license terms. So I decided to do one on my own. Which is a way much simpler to implement than any of the others commercial server side spell checkers. So here it is:

Prerequisites:

Install from Nuget NHunspell package so you would be able to use the dictionary files .aff and .dic


Usings:

using NHunspell;
using System.IO;
using System;
using System.Web;
using System.Text;
using System.Collections.Generic;


Simple ashx handler source:

   public void ProcessRequest (HttpContext context) {
        var Language = context.Request.Form["lang"];
        var Words = context.Request.Form["text"];
        var Action = context.Request.Form["method"];
        string JSON = "{\"words\": [{}]}";
        List<string> WordsList = new List<string>();
        List<Tuple<int, string>> WordsListLevenshtein = new List<Tuple<int, string>>();

        if (Language != null && Words != null && Action != null && File.Exists(context.Server.MapPath("~/Upload/Dictionaries/" + Language + ".aff")) && File.Exists(context.Server.MapPath("~/Upload/Dictionaries/" + Language + ".dic")))
        {
            Language = Functions.StripHTML(Language);
            Words = Functions.StripHTML(Words);
            Action = Functions.StripHTML(Action);

            if (Action.ToString().ToLower() == "spellcheck" && Words.Trim() != String.Empty)
            {
                JSON = "{\"words\": {";

                foreach(string Word in Words.Split(new char[0]))
                {
                    try
                    {
                        Hunspell hunspell = new Hunspell(context.Server.MapPath("~/Upload/Dictionaries/" + Language + ".aff"), context.Server.MapPath("~/Upload/Dictionaries/" + Language + ".dic"));
                     
                        if(!hunspell.Spell(Word.Trim()))
                        {
                            List<string> suggestions = hunspell.Suggest(Word.Trim());

                            if (suggestions.Count > 0)
                            {
                                foreach (string suggestion in suggestions)
                                {
                                    if (!WordsList.Contains(suggestion))
                                    {
                                        WordsList.Add(suggestion);
                                    }
                                }

                                foreach (string item in WordsList)
                                {
                                    WordsListLevenshtein.Add(new Tuple<int, string>(Functions.LevenshteinDistance(Word.Trim(), item), item));
                                }

                                WordsList.Clear();

                                WordsListLevenshtein.Sort((a, b) => b.Item1.CompareTo(a.Item1));

                                if (WordsListLevenshtein.Count > 10)
                                {
                                    WordsListLevenshtein.RemoveRange(10, WordsListLevenshtein.Count - 10);
                                }

                                JSON += "\"" + Word.Trim() + "\": [";

                                foreach (var item in WordsListLevenshtein)
                                {
                                    JSON += "\"" + item.Item2 + "\", ";
                                }

                                WordsListLevenshtein.Clear();

                                int index = JSON.LastIndexOf(',');
                                JSON = JSON.Remove(index, 1) + "], ";
                            }
                        }

                        hunspell.Dispose();
                    }
                    catch (Exception ex)
                    {
                        JSON = "{\"words\": [{\"error\": \"" + HttpUtility.JavaScriptStringEncode(ex.Message) + "\"}]}";
                    }
                }

                int lastcomma = JSON.LastIndexOf(',');

                if (lastcomma > -1)
                {
                   JSON = JSON.Remove(lastcomma, 1) + "}}";
                }
                else
                {
                   JSON = JSON + "}}";
                }
            }
        }

        context.Response.ContentEncoding = Encoding.UTF8;
        context.Response.Cache.SetExpires(DateTime.UtcNow.AddYears(-1));
        context.Response.Headers.Add("Cache-Control", "no-store, no-cache, must-revalidate");
        context.Response.Headers.Add("Pragma", "no-cache");
        context.Response.ContentType = "application/json";
        context.Response.Write(JSON);
    }


A bit of extra push and implementing Levenshtein word distance just to make sure the suggested words are ordered in the most closest first in the list.


  public static int LevenshteinDistance(string SearchString, string FoundString)
        {
            var source1Length = SearchString.Length;
            var source2Length = FoundString.Length;
            var matrix = new int[source1Length + 1, source2Length + 1];

            if (source1Length == 0)
            {
                return source2Length;
            }

            if (source2Length == 0)
            {
                return source1Length;
            }

            for (var i = 0; i <= source1Length; matrix[i, 0] = i++) { }
            for (var j = 0; j <= source2Length; matrix[0, j] = j++) { }
            for (var i = 1; i <= source1Length; i++)
            {
                for (var j = 1; j <= source2Length; j++)
                {
                    var cost = (FoundString[j - 1] == SearchString[i - 1]) ? 0 : 1;
                    matrix[i, j] = Math.Min(Math.Min(matrix[i - 1, j] + 1, matrix[i, j - 1] + 1), matrix[i - 1, j - 1] + cost);
                }
            }

            return matrix[source1Length, source2Length];

        }



And last but not least the TinyMCE init:

tinymce.init({
            selector: ".tinymce",
            plugins: ["advlist autolink lists link image charmap preview searchreplace code fullscreen   textcolor colorpicker insertdatetime table contextmenu paste textcolor nonbreaking media emoticons   importcss hr pagebreak anchor wordcount print code visualblocks visualchars spellchecker "],
        toolbar1: " spellchecker | print paste | fontselect | fontsizeselect | bold italic underline | undo redo  | styleselect | alignleft aligncenter alignright alignjustify  | forecolor  backcolor | code preview  fullscreen ",
            spellchecker_rpc_url: '<%=ResolveUrl("~/Handlers/SpellChecker.ashx") %>',
            spellchecker_languages: "Afrikaans=af,አማርኛ=am,Български=bg,Deutsch=de,Español=es,Français=fr,Македонски=mk,Românește=ro,Русский=ru,Português=pt,српски=sr,Українська мова=uk,Türkçe=tr,Polski=pl,हिन्दी=hi,ελληνικά=el,Kiswahili=sw,汉语=zh,Melayu=ms,Italiano=it,English=en",
})


Oh and one more last thing you will need your dictionaries Hunspell format .aff and .dic which you can get from the repository of the Firefox browser. And here is how to...

1. Open you Firefox browser and go to https://addons.mozilla.org/en-US/firefox/search/?platform=windows&q=spellcheck

2. Find your desired language spellcheck dictionary (make sure it is spell check dictionary not Firefox interface dictionary!).

3. Install the addon for the selected spell checking dictionary.

4. Go to %AppData%      Roaming\Mozilla\Firefox\Profiles your profile folder  than extensions folder and then you will see the dictionary file installed there (all dictionary files are *.xpi extension).

5. Copy the desired dictionary file from the profiles folder to another location (your desktop folder) and replace the extension xpi with zip and then unzip the file.

6. In the unzipped folder you will find subfolder called dictionaries which contains the *.aff and *.dic files, copy them in your projects (Upload/Dictionaries in my case) folder.

You are good to go from here on.

Let me know if it helped you or you have any suggestions.




Wednesday, August 15, 2018

World country flags icons set sprite

You know how sometimes you need to add to the application that you do some fancy flags during the language or country selection, well here are they in a nice web optimized sprite ready for use + extra CSS source for their application.





Example use of the CSS in your HTML source:
<div class="flag" id="AFG"></div> Afganistan

The countries selectors are organized by three letters ISO Code




.flag {
    display: inline-block;
    width: 32px;
    height: 32px;
    background: url('flags/small-flags.png') no-repeat;
    opacity: .7;
}

#AFG {
    background-position: -96px 0;
}

#ALB {
    background-position: -192px 0;
}

#DZA {
    background-position: -320px -96px;
}

#ASM {
    background-position: -352px 0;
}

#AND {
    background-position: -32px 0;
}

#AGO {
    background-position: -288px 0;
}

#AIA {
    background-position: -160px 0;
}

#ATG {
    background-position: -128px 0;
}

#ARG {
    background-position: -320px 0;
}

#ARM {
    background-position: -224px 0;
}

#ABW {
    background-position: -448px 0;
}

#AUS, #AUS2, #AUS3, #HMD {
    background-position: -416px 0;
}

#AUT, #AUT2 {
    background-position: -384px 0;
}

#AZE {
    background-position: 0 -32px;
}

#BHS {
    background-position: -480px -32px;
}

#BHR {
    background-position: -224px -32px;
}

#BGD, #BGD2 {
    background-position: -96px -32px;
}

#BRB {
    background-position: -64px -32px;
}

#BLR {
    background-position: -64px -64px;
}

#BEL, #BEL2 {
    background-position: -128px -32px;
}

#BLZ {
    background-position: -96px -64px;
}

#BEN {
    background-position: -288px -32px;
}

#BMU {
    background-position: -352px -32px;
}

#BTN {
    background-position: 0 -64px;
}

#BOL {
    background-position: -416px -32px;
}

#BIH {
    background-position: -32px -32px;
}

#BWA {
    background-position: -32px -64px;
}

#BRA, #BRA2 {
    background-position: -448px -32px;
}

#VGB {
    background-position: -192px -448px;
}

#BRN {
    background-position: -384px -32px;
}

#BGR {
    background-position: -192px -32px;
}

#BFA {
    background-position: -160px -32px;
}

#BDI {
    background-position: -256px -32px;
}

#KHM {
    background-position: 0 -224px;
}

#CMR {
    background-position: -384px -64px;
}

#CAN, #CAN2 {
    background-position: -128px -64px;
}

#CPV {
    background-position: -32px -96px;
}

#CYM {
    background-position: -224px -224px;
}

#CAF {
    background-position: -192px -64px;
}

#TCD {
    background-position: -480px -384px;
}

#CHL {
    background-position: -352px -64px;
}

#CHN, #CHN2, #CHN3, #CHN4, #CHN5, #CHN6 {
    background-position: -416px -64px;
}

#COL, #COL2 {
    background-position: -448px -64px;
}

#COM {
    background-position: -64px -224px;
}

#COD {
    background-position: -160px -64px;
}

#COG {
    background-position: -224px -64px;
}

#COK {
    background-position: -320px -64px;
}

#CRI {
    background-position: -480px -64px;
}

#CIV, #CIV2 {
    background-position: -288px -64px;
}

#HRV {
    background-position: -416px -160px;
}

#CUB {
    background-position: 0 -96px;
}

#CYP, #CYP2 {
    background-position: -96px -96px;
}

#CZE, #CZE2 {
    background-position: -128px -96px;
}

#DNK, #DNK2 {
    background-position: -224px -96px;
}

#DJI {
    background-position: -192px -96px;
}

#DMA {
    background-position: -256px -96px;
}

#DOM {
    background-position: -288px -96px;
}

#TLS {
    background-position: -160px -416px;
}

#ECU {
    background-position: -352px -96px;
}

#EGY {
    background-position: -416px -96px;
}

#SLV {
    background-position: -352px -384px;
}

#GNQ {
    background-position: -128px -160px;
}

#ERI {
    background-position: -480px -96px;
}

#EST, #EST2 {
    background-position: -384px -96px;
}

#ETH {
    background-position: -32px -128px;
}

#FLK {
    background-position: -160px -128px;
}

#FRO {
    background-position: -224px -128px;
}

#FJI {
    background-position: -128px -128px;
}

#FIN, #FIN2 {
    background-position: -96px -128px;
}

#FRA, #FRA2, #REU, #GUF, #ATF, #GLP, #NCL, #MYT, #MAF {
    background-position: -256px -128px;
}

#PYF {
    background-position: -320px -320px;
}

#GAB {
    background-position: -288px -128px;
}

#GMB {
    background-position: -32px -160px;
}

#GEO {
    background-position: -384px -128px;
}

#DEU, #DEU2 {
    background-position: -160px -96px;
}

#GHA {
    background-position: -448px -128px;
}

#GIB {
    background-position: -480px -128px;
}

#GRC, #GRC2 {
    background-position: -160px -160px;
}

#GRL {
    background-position: 0 -160px;
}

#GRD {
    background-position: -352px -128px;
}

#GUM {
    background-position: -256px -160px;
}

#GTM {
    background-position: -224px -160px;
}

#GIN {
    background-position: -64px -160px;
}

#GNB {
    background-position: -288px -160px;
}

#GUY {
    background-position: -320px -160px;
}

#HTI {
    background-position: -448px -160px;
}

#HND {
    background-position: -384px -160px;
}

#HKG {
    background-position: -352px -160px;
}

#HUN, #HUN2 {
    background-position: -480px -160px;
}

#ISL, #ISL2 {
    background-position: -256px -192px;
}

#IND, #IND2 {
    background-position: -160px -192px;
}

#IDN, #IDN2 {
    background-position: -32px -192px;
}

#IRN {
    background-position: -224px -192px;
}

#IRQ {
    background-position: -192px -192px;
}

#IRL, #IRL2 {
    background-position: -64px -192px;
}

#ISR, #ISR2 {
    background-position: -96px -192px;
}

#ITA, #ITA2 {
    background-position: -288px -192px;
}

#JAM {
    background-position: -352px -192px;
}

#JPN, #JPN2 {
    background-position: -416px -192px;
}

#JOR {
    background-position: -384px -192px;
}

#KAZ {
    background-position: -256px -224px;
}

#KEN {
    background-position: -448px -192px;
}

#KIR {
    background-position: -32px -224px;
}

#PRK {
    background-position: -128px -224px;
}

#KOR, #KOR2 {
    background-position: -160px -224px;
}

#KWT {
    background-position: -192px -224px;
}

#KGZ {
    background-position: -480px -192px;
}

#LAO {
    background-position: -288px -224px;
}

#LVA {
    background-position: -64px -256px;
}

#LBN {
    background-position: -320px -224px;
}

#LSO {
    background-position: -480px -224px;
}

#LBR {
    background-position: -448px -224px;
}

#LBY {
    background-position: -96px -256px;
}

#LIE {
    background-position: -384px -224px;
}

#LTU, #LTU2 {
    background-position: 0 -256px;
}

#LUX, #LUX2 {
    background-position: -32px -256px;
}

#MAC {
    background-position: -480px -256px;
}

#MKD {
    background-position: -352px -256px;
}

#MDG {
    background-position: -288px -256px;
}

#MWI {
    background-position: -224px -288px;
}

#MYS, #MYS2 {
    background-position: -288px -288px;
}

#MDV {
    background-position: -192px -288px;
}

#MLI {
    background-position: -384px -256px;
}

#MLT {
    background-position: -128px -288px;
}

#MHL {
    background-position: -320px -256px;
}

#MTQ {
    background-position: -32px -288px;
}

#MRT {
    background-position: -64px -288px;
}

#MUS {
    background-position: -160px -288px;
}

#MEX {
    background-position: -256px -288px;
}

#FSM {
    background-position: -192px -128px;
}

#MDA {
    background-position: -192px -256px;
}

#MCO {
    background-position: -160px -256px;
}

#MNG {
    background-position: -448px -256px;
}

#MNE {
    background-position: -224px -256px;
}

#MSR {
    background-position: -96px -288px;
}

#MAR {
    background-position: -128px -256px;
}

#MOZ {
    background-position: -320px -288px;
}

#MMR {
    background-position: -416px -256px;
}

#MMR2 {
    background-position: -160px -156px;
}

#NAM {
    background-position: -352px -288px;
}

#NRU {
    background-position: -128px -320px;
}

#NPL {
    background-position: -96px -320px;
}

#NLD, #NLD2, #ANT {
    background-position: -256px 0;
}

#NZL {
    background-position: -192px -320px;
}

#NIC {
    background-position: 0 -320px;
}

#NER {
    background-position: -416px -288px;
}

#NGA {
    background-position: -480px -288px;
}

#NIU {
    background-position: -160px -320px;
}

#MNP {
    background-position: 0 -288px;
}

#NOR, #NOR2, #SJM, #BVT {
    background-position: -64px -320px;
}

#OMN {
    background-position: -224px -320px;
}

#PAK {
    background-position: -416px -320px;
}

#PLW {
    background-position: -96px -352px;
}

#PSE {
    background-position: -32px -352px;
}

#PAN {
    background-position: -256px -320px;
}

#PNG {
    background-position: -352px -320px;
}

#PRY {
    background-position: -128px -352px;
}

#PER {
    background-position: -288px -320px;
}

#PHL {
    background-position: -384px -320px;
}

#PCN {
    background-position: -480px -320px;
}

#POL, #POL2 {
    background-position: -448px -320px;
}

#PRT {
    background-position: -64px -352px;
}

#PRI {
    background-position: 0 -352px;
}

#QAT {
    background-position: -160px -352px;
}

#ROU {
    background-position: -224px -352px;
}

#RUS, #RUS2, #RUS3 {
    background-position: -288px -352px;
}

#RWA {
    background-position: -320px -352px;
}

#SHN {
    background-position: -32px -384px;
}

#TDC {
    background-position: -160px -192px;
}

#KNA {
    background-position: -96px -224px;
}

#LCA {
    background-position: -352px -224px;
}

#SPM {
    background-position: -20px -204px;
}

#VCT {
    background-position: -128px -448px;
}

#WSM {
    background-position: -352px -448px;
}

#SMR {
    background-position: -160px -384px;
}

#STP {
    background-position: -320px -384px;
}

#SAU {
    background-position: -352px -352px;
}

#SEN {
    background-position: -192px -384px;
}

#SRB {
    background-position: -256px -352px;
}

#SYC {
    background-position: -416px -352px;
}

#SLE {
    background-position: -128px -384px;
}

#SGP {
    background-position: 0 -384px;
}

#SVK, #SVK2 {
    background-position: -96px -384px;
}

#SVN, #SVN2 {
    background-position: -64px -384px;
}

#SLB {
    background-position: -384px -352px;
}

#SOM {
    background-position: -224px -384px;
}

#ZAF {
    background-position: -448px -448px;
}

#SSD {
    background-position: -288px -384px;
}

#ESP, #ESP2 {
    background-position: 0 -128px;
}

#LKA {
    background-position: -416px -224px;
}

#SDN {
    background-position: -448px -352px;
}

#SUR {
    background-position: -256px -384px;
}

#SWZ {
    background-position: -416px -384px;
}

#SWE, #SWE2 {
    background-position: -480px -352px;
}

#CHE, #CHE2 {
    background-position: -256px -64px;
}

#SYR {
    background-position: -384px -384px;
}

#TWN {
    background-position: -384px -416px;
}

#TJK {
    background-position: -96px -416px;
}

#TZA {
    background-position: -416px -416px;
}

#THA {
    background-position: -64px -416px;
}

#TIBET {
    background-position: -20px -240px;
}

#TLS {
    background-position: -40px -240px;
}

#TLS2 {
    background-position: -40px -240px;
}

#TGO {
    background-position: -32px -416px;
}

#TKL {
    background-position: -128px -416px;
}

#TON {
    background-position: -256px -416px;
}

#TTO {
    background-position: -320px -416px;
}

#TUN {
    background-position: -224px -416px;
}

#TUR {
    background-position: -288px -416px;
}

#TKM {
    background-position: -192px -416px;
}

#TCA {
    background-position: -448px -384px;
}

#TUV {
    background-position: -352px -416px;
}

#UGA {
    background-position: -480px -416px;
}

#UKR {
    background-position: -448px -416px;
}

#ARE {
    background-position: -64px 0;
}

#GBR, #GBR2, #GBR3, #GBR4, #GBR5, #ACI {
    background-position: -320px -128px;
}

#USA, #USA2, #USA3, #USA4, #USA5, #USA6, #USA7, #USA8, #USA9, #USA10, #USA11, #USA12, #USA13, #USA14, #USA15, #USA16 {
    background-position: 0 -448px;
}

#UMI {
    background-position: -120px -252px;
}

#URY {
    background-position: -32px -448px;
}

#UZB {
    background-position: -64px -448px;
}

#VUT {
    background-position: -288px -448px;
}

#VAT {
    background-position: -96px -448px;
}

#VA {
    background-position: 0px -264px;
}

#VEN {
    background-position: -160px -448px;
}

#VNM {
    background-position: -256px -448px;
}

#VIR {
    background-position: -224px -448px;
}

#WLF {
    background-position: -320px -448px;
}

#ESH {
    background-position: -448px -96px;
}

#YEM {
    background-position: -384px -448px;
}

#ZMB {
    background-position: -480px -448px;
}

#ZWE {
    background-position: 0 -480px;
}

#IOT {
    background-position: -180px -264px;
}

#CXR {
    background-position: 0px -276px;
}

#CCK {
    background-position: -20px -276px;
}

#GGY {
    background-position: -416px -128px;
}

#IMN {
    background-position: -128px -192px;
}

#JEY {
    background-position: -320px -192px;
}

#NFK {
    background-position: -448px -288px;
}

#BLM {
    background-position: -320px -32px;
}

#SGS {
    background-position: -192px -160px;
}

#EUR {
    background-position: -64px -128px;
}

#SEG {
    background-position: 0px 0px;
}

Tuesday, August 14, 2018

World currencies SQL database

Well as the title of the post says here I would like to share with you CSV file (it's easy to import or convert to any other database format) containing all world currencies up to date (14th of August 2018), including ISO code, English name, Native name and Abbreviation (Currency symbol) if available.

Download World Currencies CSV File


Spelling month name in Bulgarian, Russian, Spanish, Macedonian, English and Afrikaans in C#

Here it goes another piece of source code which I did for spelling month name by it's number and language ID.
Hopefully it would save you same time.


        /// <summary>
        /// Spell month name in selected language.
        /// </summary>
        /// <param name="Month">int</param>
        /// <param name="Language">string</param>
        /// <returns>string</returns>
        public static string SpellMonth(int Month, string Language)
        {
            string MonthName = String.Empty;

            if (Language == "en")
            {
                switch (Month)
                {
                    case 1:
                        MonthName = "January";
                        break;
                    case 2:
                        MonthName = "February";
                        break;
                    case 3:
                        MonthName = "March";
                        break;
                    case 4:
                        MonthName = "April";
                        break;
                    case 5:
                        MonthName = "May";
                        break;
                    case 6:
                        MonthName = "June";
                        break;
                    case 7:
                        MonthName = "July";
                        break;
                    case 8:
                        MonthName = "August";
                        break;
                    case 9:
                        MonthName = "September";
                        break;
                    case 10:
                        MonthName = "October";
                        break;
                    case 11:
                        MonthName = "November";
                        break;
                    case 12:
                        MonthName = "December";
                        break;
                    default:
                        break;
                }
            }
            else if (Language == "af")
            {
                switch (Month)
                {
                    case 1:
                        MonthName = "Januarie";
                        break;
                    case 2:
                        MonthName = "Februarie";
                        break;
                    case 3:
                        MonthName = "Maart";
                        break;
                    case 4:
                        MonthName = "April";
                        break;
                    case 5:
                        MonthName = "Mei";
                        break;
                    case 6:
                        MonthName = "Junie";
                        break;
                    case 7:
                        MonthName = "Julie";
                        break;
                    case 8:
                        MonthName = "Augustus";
                        break;
                    case 9:
                        MonthName = "September";
                        break;
                    case 10:
                        MonthName = "Oktober";
                        break;
                    case 11:
                        MonthName = "November";
                        break;
                    case 12:
                        MonthName = "Desember";
                        break;
                    default:
                        break;
                }
            }
            else if (Language == "mk")
            {
                switch (Month)
                {
                    case 1:
                        MonthName = "Јануари";
                        break;
                    case 2:
                        MonthName = "Февруари";
                        break;
                    case 3:
                        MonthName = "Март";
                        break;
                    case 4:
                        MonthName = "Април";
                        break;
                    case 5:
                        MonthName = "Мај";
                        break;
                    case 6:
                        MonthName = "Јуни";
                        break;
                    case 7:
                        MonthName = "Јули";
                        break;
                    case 8:
                        MonthName = "Август";
                        break;
                    case 9:
                        MonthName = "Септември";
                        break;
                    case 10:
                        MonthName = "Октомври";
                        break;
                    case 11:
                        MonthName = "Ноември";
                        break;
                    case 12:
                        MonthName = "Декември";
                        break;
                    default:
                        break;
                }
            }
            else if (Language == "es")
            {
                switch (Month)
                {
                    case 1:
                        MonthName = "enero";
                        break;
                    case 2:
                        MonthName = "febrero";
                        break;
                    case 3:
                        MonthName = "marzo";
                        break;
                    case 4:
                        MonthName = "abril";
                        break;
                    case 5:
                        MonthName = "mayo";
                        break;
                    case 6:
                        MonthName = "junio";
                        break;
                    case 7:
                        MonthName = "julio";
                        break;
                    case 8:
                        MonthName = "agosto";
                        break;
                    case 9:
                        MonthName = "septimebre";
                        break;
                    case 10:
                        MonthName = "octubre";
                        break;
                    case 11:
                        MonthName = "noviembre";
                        break;
                    case 12:
                        MonthName = "diciembre";
                        break;
                    default:
                        break;
                }
            }
            else if (Language == "bg")
            {
                switch (Month)
                {
                    case 1:
                        MonthName = "януари";
                        break;
                    case 2:
                        MonthName = "февруари";
                        break;
                    case 3:
                        MonthName = "март";
                        break;
                    case 4:
                        MonthName = "април";
                        break;
                    case 5:
                        MonthName = "май";
                        break;
                    case 6:
                        MonthName = "юни";
                        break;
                    case 7:
                        MonthName = "юли";
                        break;
                    case 8:
                        MonthName = "август";
                        break;
                    case 9:
                        MonthName = "септември";
                        break;
                    case 10:
                        MonthName = "октомври";
                        break;
                    case 11:
                        MonthName = "ноември";
                        break;
                    case 12:
                        MonthName = "декември";
                        break;
                    default:
                        break;
                }
            }
            else if (Language == "ru")
            {
                switch (Month)
                {
                    case 1:
                        MonthName = "январь";
                        break;
                    case 2:
                        MonthName = "февраль";
                        break;
                    case 3:
                        MonthName = "март";
                        break;
                    case 4:
                        MonthName = "апрель";
                        break;
                    case 5:
                        MonthName = "май";
                        break;
                    case 6:
                        MonthName = "июнь";
                        break;
                    case 7:
                        MonthName = "июль";
                        break;
                    case 8:
                        MonthName = "август";
                        break;
                    case 9:
                        MonthName = "сентябрь";
                        break;
                    case 10:
                        MonthName = "октябрь";
                        break;
                    case 11:
                        MonthName = "ноябрь";
                        break;
                    case 12:
                        MonthName = "декабрь";
                        break;
                    default:
                        break;
                }
            }

            return MonthName;
        }

Spelling numbers in Bulgarian, Russian, Spanish, Macedonian, English and Afrikaans in C#

A couple of weeks ago I needed to spell numbers for a project that I am currently working on. Today I thought that it could be a good idea to share code for spelling numbers in C# and .Net in couple of languages (Bulgarian, Russian, Spanish, Macedonian, English, Afrikaans). So here it goes:


   #region Bulgarian numbers
        /// <summary>
        /// Converts digits to bulgarian words.
        /// </summary>
        /// <param name="value">int64</param>
        /// <returns>string</returns>
        private static string ConvertDigitBulgarian(Int64 value)
        {
            string str = String.Empty;
            if (value < 0)
            {
                return string.Concat("минус ", ConvertDigitBulgarian(Math.Abs(value)));
            }
            if (value == 0)
            {
                str = "нула";
            }
            else if (value == 1)
            {
                str = "едно";
            }
            else if (value == 2)
            {
                str = "две";
            }
            else if (value == 3)
            {
                str = "три";
            }
            else if (value == 4)
            {
                str = "четири";
            }
            else if (value == 5)
            {
                str = "пет";
            }
            else if (value == 6)
            {
                str = "шест";
            }
            else if (value == 7)
            {
                str = "седем";
            }
            else if (value == 8)
            {
                str = "осем";
            }
            else if (value == 9)
            {
                str = "девет";
            }
            else if (value == 10)
            {
                str = "десет";
            }
            else if (value == 11)
            {
                str = "единадесет";
            }
            else if (value == 12)
            {
                str = "дванадесет";
            }
            else if (value == 13)
            {
                str = "тринадесет";
            }
            else if (value == 14)
            {
                str = "четиринадесет";
            }
            else if (value == 15)
            {
                str = "петнадесет";
            }
            else if (value == 16)
            {
                str = "шестнадесет";
            }
            else if (value == 17)
            {
                str = "седемнадесет";
            }
            else if (value == 18)
            {
                str = "осемнадесет";
            }
            else if (value == 19)
            {
                str = "деветнадесет";
            }
            else if (value < 20)
            {
                str = string.Concat(" двадесет", ConvertDigitBulgarian(value - 10));
            }
            else if (value == 20)
            {
                str = " двадесет";
            }
            else if (value < 30)
            {
                str = string.Concat(" двадесет и ", ConvertDigitBulgarian(value - 20));
            }
            else if (value == 30)
            {
                str = " тридесет";
            }
            else if (value < 40)
            {
                str = string.Concat(" тридесет и ", ConvertDigitBulgarian(value - 30));
            }
            else if (value == 40)
            {
                str = " четиридесет";
            }
            else if (value < 50)
            {
                str = string.Concat(" четиридесет и ", ConvertDigitBulgarian(value - 40));
            }
            else if (value == 50)
            {
                str = " петдесет";
            }
            else if (value < 60)
            {
                str = string.Concat(" петдесет и ", ConvertDigitBulgarian(value - 50));
            }
            else if (value == 60)
            {
                str = " шестдесет";
            }
            else if (value < 70)
            {
                str = string.Concat(" шестдесет и ", ConvertDigitBulgarian(value - 60));
            }
            else if (value == 70)
            {
                str = " седемдесет";
            }
            else if (value < 80)
            {
                str = string.Concat(" седемдесет и ", ConvertDigitBulgarian(value - 70));
            }
            else if (value == 80)
            {
                str = " осемдесет";
            }
            else if (value < 90)
            {
                str = string.Concat(" осемдесет и ", ConvertDigitBulgarian(value - 80));
            }
            else if (value == 90)
            {
                str = " деветдесет";
            }
            else if (value < 100)
            {
                str = string.Concat(" деветдесет и ", ConvertDigitBulgarian(value - 90));
            }
            else if (value < 100)
            {
                Int64 num = value % 10;
                str = string.Format("{0} {1}", ConvertDigitBulgarian(value / 10 * 10), (num == 1 ? "сто и" : ConvertDigitBulgarian(value % 10)));
            }
            else if (value == 100)
            {
                str = " сто";
            }
            else if (value < 200)
            {
                str = string.Concat(" сто и ", ConvertDigitBulgarian(value - 100));
            }
            else if (value == 200 || value == 300)
            {
                str = string.Concat(ConvertDigitBulgarian(value / 100), "ста");
            }
            else if (value == 400 || value == 600 || value == 800 || value == 500 || value == 700 || value == 900)
            {
                str = string.Concat(ConvertDigitBulgarian(value / 100), "стотин");
            }
            else if (value < 1000)
            {
                str = string.Format("{0} {1}", ConvertDigitBulgarian(value / 100 * 100), ConvertDigitBulgarian(value % 100));
            }
            else if (value == 1000)
            {
                str = " хиляда";
            }
            else if (value < 2000)
            {
                str = string.Concat(" хиляда и ", ConvertDigitBulgarian(value % 1000));
            }
            else if (value < 1000000)
            {
                str = string.Concat(ConvertDigitBulgarian(value / 1000), " хиляди");
                if (value % 1000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitBulgarian(value % 1000));
                }
            }
            else if (value == 1000000)
            {
                str = " един милион";
            }
            else if (value < 2000000)
            {
                str = string.Concat(" един милион ", ConvertDigitBulgarian(value % 1000000));
            }
            else if (value < 1000000000)
            {
                str = string.Concat(ConvertDigitBulgarian(value / 1000000), " милиона");
                if (value - value / 1000000 * 1000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitBulgarian(value - value / 1000000 * 1000000));
                }
            }
            else if (value == 1000000000)
            {
                str = " един милиард";
            }
            else if (value < 2000000000)
            {
                str = string.Concat("един милиард ", ConvertDigitBulgarian(value % 1000000000));
            }
            else if (value < 1000000000000)
            {
                str = string.Concat(ConvertDigitBulgarian(value / 1000000000), " милиарда");
                if (value - value / 1000000000 * 1000000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitBulgarian(value - value / 1000000000 * 1000000000));
                }
            }
            else if (value == 1000000000000)
            {
                str = " един трилион";
            }
            else if (value < 2000000000000)
            {
                str = string.Concat(" един трилион ", ConvertDigitBulgarian(value % 1000000000000));
            }
            else if (value < 1000000000000000)
            {
                str = string.Concat(ConvertDigitBulgarian(value / 1000000000000), " трилиона");
                if (value - value / 1000000000000 * 1000000000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitBulgarian(value - value / 1000000000000 * 1000000000000));
                }
            }

            return str;
        }


        /// <summary>
        /// Spells numbers in blugarian language.
        /// </summary>
        /// <param name="Value"></param>
        /// <returns>string</returns>
        private static string SpellNumberInBulgarian(double Value)
        {
            Int64 num = (Int64)Value;
            string str = Value.ToString("0.00#");
            char[] chrArray = new char[] { ',' };
            string str1 = str.Split(chrArray)[1];
            Int64 num1 = Int64.Parse(str1);
            if (num1 == 0)
            {
                return ConvertDigitBulgarian(num);
            }
            return string.Format("{0} точка {1} ", ConvertDigitBulgarian(num), ConvertDigitBulgarian(num1));
        }
        #endregion







        #region Russian numbers
        /// <summary>
        /// Converts digits to russian words.
        /// </summary>
        /// <param name="value">int64</param>
        /// <returns>string</returns>
        private static string ConvertDigitRussian(Int64 value)
        {
            string str = String.Empty;
            if (value < 0)
            {
                return string.Concat("минус ", ConvertDigitRussian(Math.Abs(value)));
            }
            if (value == 0)
            {
                str = "нуль";
            }
            else if (value == 1)
            {
                str = "один";
            }
            else if (value == 2)
            {
                str = "два";
            }
            else if (value == 3)
            {
                str = "три";
            }
            else if (value == 4)
            {
                str = "четыре";
            }
            else if (value == 5)
            {
                str = "пять";
            }
            else if (value == 6)
            {
                str = "шесть";
            }
            else if (value == 7)
            {
                str = "семь";
            }
            else if (value == 8)
            {
                str = "восемь";
            }
            else if (value == 9)
            {
                str = "девять";
            }
            else if (value == 10)
            {
                str = "десять";
            }
            else if (value == 11)
            {
                str = "одиннадцать";
            }
            else if (value == 12)
            {
                str = "двенадцать";
            }
            else if (value == 13)
            {
                str = "тринадцать";
            }
            else if (value == 14)
            {
                str = "четырнадцать";
            }
            else if (value == 15)
            {
                str = "пятнадцать";
            }
            else if (value == 16)
            {
                str = "шестнадцать";
            }
            else if (value == 17)
            {
                str = "семнадцать";
            }
            else if (value == 18)
            {
                str = "восемнадцать";
            }
            else if (value == 19)
            {
                str = "девятнадцать";
            }
            else if (value < 20)
            {
                str = string.Concat(" двадцать", ConvertDigitRussian(value - 10));
            }
            else if (value == 20)
            {
                str = " двадцать";
            }
            else if (value < 30)
            {
                str = string.Concat(" двадцать ", ConvertDigitRussian(value - 20));
            }
            else if (value == 30)
            {
                str = " тридцать";
            }
            else if (value < 40)
            {
                str = string.Concat(" тридцать ", ConvertDigitRussian(value - 30));
            }
            else if (value == 40)
            {
                str = " сорок";
            }
            else if (value < 50)
            {
                str = string.Concat(" сорок ", ConvertDigitRussian(value - 40));
            }
            else if (value == 50)
            {
                str = " пятьдесят";
            }
            else if (value < 60)
            {
                str = string.Concat(" пятьдесят ", ConvertDigitRussian(value - 50));
            }
            else if (value == 60)
            {
                str = " шестьдесят";
            }
            else if (value < 70)
            {
                str = string.Concat(" шестьдесят ", ConvertDigitRussian(value - 60));
            }
            else if (value == 70)
            {
                str = " семьдесят";
            }
            else if (value < 80)
            {
                str = string.Concat(" семьдесят ", ConvertDigitRussian(value - 70));
            }
            else if (value == 80)
            {
                str = " восемьдесят";
            }
            else if (value < 90)
            {
                str = string.Concat(" восемьдесят ", ConvertDigitRussian(value - 80));
            }
            else if (value == 90)
            {
                str = " девяносто";
            }
            else if (value < 100)
            {
                str = string.Concat(" девяносто ", ConvertDigitRussian(value - 90));
            }
            else if (value < 100)
            {
                Int64 num = value % 10;
                str = string.Format("{0} {1}", ConvertDigitRussian(value / 10 * 10), (num == 1 ? "сто " : ConvertDigitRussian(value % 10)));
            }
            else if (value == 100)
            {
                str = " сто";
            }
            else if (value < 200)
            {
                str = string.Concat(" сто ", ConvertDigitRussian(value - 100));
            }
            else if (value == 200)
            {
                str = " двести";
            }
            else if (value < 300)
            {
                str = string.Concat(" двести ", ConvertDigitRussian(value - 200));
            }
            else if (value == 300)
            {
                str = " триста";
            }
            else if (value < 400)
            {
                str = string.Concat(" триста ", ConvertDigitRussian(value - 300));
            }
            else if (value == 400)
            {
                str = " четыреста";
            }
            else if (value < 500)
            {
                str = string.Concat(" четыреста ", ConvertDigitRussian(value - 400));
            }
            else if (value == 500 || value == 600 || value == 700 || value == 800 || value == 900)
            {
                str = string.Concat(ConvertDigitRussian(value / 100), "сот");
            }
            else if (value < 1000)
            {
                str = string.Format("{0} {1}", ConvertDigitRussian(value / 100 * 100), ConvertDigitRussian(value % 100));
            }
            else if (value == 1000)
            {
                str = " одна тысяча";
            }
            else if (value < 2000)
            {
                str = string.Concat(" одна тысяча ", ConvertDigitRussian(value % 1000));
            }
            else if (value < 1000000)
            {
                str = string.Concat(ConvertDigitRussian(value / 1000), " тысяч");
                if (value % 1000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitRussian(value % 1000));
                }
            }
            else if (value == 1000000)
            {
                str = " один миллион";
            }
            else if (value < 2000000)
            {
                str = string.Concat(" один миллион ", ConvertDigitRussian(value % 1000000));
            }
            else if (value < 1000000000)
            {
                str = string.Concat(ConvertDigitRussian(value / 1000000), " миллиона");
                if (value - value / 1000000 * 1000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitRussian(value - value / 1000000 * 1000000));
                }
            }
            else if (value == 1000000000)
            {
                str = " один миллиард";
            }
            else if (value < 2000000000)
            {
                str = string.Concat("один миллиард ", ConvertDigitRussian(value % 1000000000));
            }
            else if (value < 1000000000000)
            {
                str = string.Concat(ConvertDigitRussian(value / 1000000000), " миллиарда");
                if (value - value / 1000000000 * 1000000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitRussian(value - value / 1000000000 * 1000000000));
                }
            }
            else if (value == 1000000000000)
            {
                str = " один триллион";
            }
            else if (value < 2000000000000)
            {
                str = string.Concat(" один триллион ", ConvertDigitRussian(value % 1000000000000));
            }
            else if (value < 1000000000000000)
            {
                str = string.Concat(ConvertDigitRussian(value / 1000000000000), " триллиона");
                if (value - value / 1000000000000 * 1000000000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitRussian(value - value / 1000000000000 * 1000000000000));
                }
            }

            return str;
        }


        /// <summary>
        /// Spells numbers in russian language.
        /// </summary>
        /// <param name="Value"></param>
        /// <returns>string</returns>
        private static string SpellNumberInRussian(double Value)
        {
            Int64 num = (Int64)Value;
            string str = Value.ToString("0.00#");
            char[] chrArray = new char[] { ',' };
            string str1 = str.Split(chrArray)[1];
            Int64 num1 = Int64.Parse(str1);
            if (num1 == 0)
            {
                return ConvertDigitRussian(num);
            }
            return string.Format("{0} точка {1} ", ConvertDigitRussian(num), ConvertDigitRussian(num1));
        }
        #endregion





        #region Spanish numbers
        /// <summary>
        /// Converts digits to spanish words.
        /// </summary>
        /// <param name="value">int64</param>
        /// <returns>string</returns>
        private static string ConvertDigitSpanish(Int64 value)
        {
            string str = String.Empty;
            if (value < 0)
            {
                return string.Concat("menos ", ConvertDigitSpanish(Math.Abs(value)));
            }
            if (value == 0)
            {
                str = "cero";
            }
            else if (value == 1)
            {
                str = "uno";
            }
            else if (value == 2)
            {
                str = "dos";
            }
            else if (value == 3)
            {
                str = "tres";
            }
            else if (value == 4)
            {
                str = "cuatro";
            }
            else if (value == 5)
            {
                str = "cinco";
            }
            else if (value == 6)
            {
                str = "seis";
            }
            else if (value == 7)
            {
                str = "siete";
            }
            else if (value == 8)
            {
                str = "ocho";
            }
            else if (value == 9)
            {
                str = "nueve";
            }
            else if (value == 10)
            {
                str = "diez";
            }
            else if (value == 11)
            {
                str = "once";
            }
            else if (value == 12)
            {
                str = "doce";
            }
            else if (value == 13)
            {
                str = "trece";
            }
            else if (value == 14)
            {
                str = "catorce";
            }
            else if (value == 15)
            {
                str = "quince";
            }
            else if (value == 16)
            {
                str = "dieciséis";
            }
            else if (value < 20)
            {
                str = string.Concat("dieci", ConvertDigitSpanish(value - 10));
            }
            else if (value == 20)
            {
                str = "veinte";
            }
            else if (value < 30)
            {
                str = string.Concat("veinti", ConvertDigitSpanish(value - 20));
            }
            else if (value == 30)
            {
                str = "treinta";
            }
            else if (value == 40)
            {
                str = "cuarenta";
            }
            else if (value == 50)
            {
                str = "cincuenta";
            }
            else if (value == 60)
            {
                str = "sesenta";
            }
            else if (value == 70)
            {
                str = "setenta";
            }
            else if (value == 80)
            {
                str = "ochenta";
            }
            else if (value == 90)
            {
                str = "noventa";
            }
            else if (value < 100)
            {
                Int64 num = value % 10;
                str = string.Format("{0} y {1}", ConvertDigitSpanish(value / 10 * 10), (num == 1 ? "un" : ConvertDigitSpanish(value % 10)));
            }
            else if (value == 100)
            {
                str = "cien";
            }
            else if (value < 200)
            {
                str = string.Concat("ciento ", ConvertDigitSpanish(value - 100));
            }
            else if (value == 200 || value == 300 || value == 400 || value == 600 || value == 800)
            {
                str = string.Concat(ConvertDigitSpanish(value / 100), "cientos");
            }
            else if (value == 500)
            {
                str = "quinientos";
            }
            else if (value == 700)
            {
                str = "setecientos";
            }
            else if (value == 900)
            {
                str = "novecientos";
            }
            else if (value < 1000)
            {
                str = string.Format("{0} {1}", ConvertDigitSpanish(value / 100 * 100), ConvertDigitSpanish(value % 100));
            }
            else if (value == 1000)
            {
                str = "mil";
            }
            else if (value < 2000)
            {
                str = string.Concat("mil ", ConvertDigitSpanish(value % 1000));
            }
            else if (value < 1000000)
            {
                str = string.Concat(ConvertDigitSpanish(value / 1000), " mil");
                if (value % 1000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitSpanish(value % 1000));
                }
            }
            else if (value == 1000000)
            {
                str = "un millón";
            }
            else if (value < 2000000)
            {
                str = string.Concat("un millón ", ConvertDigitSpanish(value % 1000000));
            }
            else if (value < 1000000000)
            {
                str = string.Concat(ConvertDigitSpanish(value / 1000000), " millones");
                if (value - value / 1000000 * 1000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitSpanish(value - value / 1000000 * 1000000));
                }
            }
            else if (value == 1000000000)
            {
                str = "un billón";
            }
            else if (value < 2000000000)
            {
                str = string.Concat("un billón ", ConvertDigitSpanish(value % 1000000000));
            }
            else if (value < 1000000000000)
            {
                str = string.Concat(ConvertDigitSpanish(value / 1000000000), " billónes");
                if (value - value / 1000000000 * 1000000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitSpanish(value - value / 1000000000 * 1000000000));
                }
            }
            else if (value == 1000000000000)
            {
                str = "un trillón";
            }
            else if (value < 2000000000000)
            {
                str = string.Concat("un trillón ", ConvertDigitSpanish(value % 1000000000000));
            }
            else if (value < 1000000000000000)
            {
                str = string.Concat(ConvertDigitSpanish(value / 1000000000000), " trillónes");
                if (value - value / 1000000000000 * 1000000000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitSpanish(value - value / 1000000000000 * 1000000000000));
                }
            }

            return str;
        }


        /// <summary>
        /// Spells numbers in spanish language.
        /// </summary>
        /// <param name="Value"></param>
        /// <returns>string</returns>
        private static string SpellNumberInSpanish(double Value)
        {
            Int64 num = (Int64)Value;
            string str = Value.ToString("0.00#");
            char[] chrArray = new char[] { ',' };
            string str1 = str.Split(chrArray)[1];
            Int64 num1 = Int64.Parse(str1);
            if (num1 == 0)
            {
                return ConvertDigitSpanish(num);
            }
            return string.Format("{0} coma {1} ", ConvertDigitSpanish(num), ConvertDigitSpanish(num1));
        }
        #endregion




        #region Macedonian numbers
        /// <summary>
        /// Converts digits to macedonian words.
        /// </summary>
        /// <param name="value">int64</param>
        /// <returns>string</returns>
        private static string ConvertDigitMacedonian(Int64 value)
        {
            string str = String.Empty;
            if (value < 0)
            {
                return string.Concat("минус ", ConvertDigitMacedonian(Math.Abs(value)));
            }
            if (value == 0)
            {
                str = "нула";
            }
            else if (value == 1)
            {
                str = "еден";
            }
            else if (value == 2)
            {
                str = "два";
            }
            else if (value == 3)
            {
                str = "три";
            }
            else if (value == 4)
            {
                str = "четири";
            }
            else if (value == 5)
            {
                str = "пет";
            }
            else if (value == 6)
            {
                str = "шест";
            }
            else if (value == 7)
            {
                str = "седум";
            }
            else if (value == 8)
            {
                str = "осум";
            }
            else if (value == 9)
            {
                str = "девет";
            }
            else if (value == 10)
            {
                str = "десет";
            }
            else if (value == 11)
            {
                str = "единаесет";
            }
            else if (value == 12)
            {
                str = "дванаесет";
            }
            else if (value == 13)
            {
                str = "тринаесет";
            }
            else if (value == 14)
            {
                str = "четиринаесет";
            }
            else if (value == 15)
            {
                str = "петнаесет";
            }
            else if (value == 16)
            {
                str = "шеснаесет";
            }
            else if (value == 17)
            {
                str = "седумнаесет";
            }
            else if (value == 18)
            {
                str = "осумнаесет";
            }
            else if (value == 19)
            {
                str = "деветнаесет";
            }
            else if (value == 20)
            {
                str = "дваесет";
            }
            else if (value < 30)
            {
                str = string.Concat(" дваесет и ", ConvertDigitMacedonian(value - 20));
            }
            else if (value == 30)
            {
                str = " триесет";
            }
            else if (value < 40)
            {
                str = string.Concat(" триесет и ", ConvertDigitMacedonian(value - 30));
            }
            else if (value == 40)
            {
                str = " четириесет";
            }
            else if (value < 50)
            {
                str = string.Concat(" четириесет и ", ConvertDigitMacedonian(value - 40));
            }
            else if (value == 50)
            {
                str = " педесет";
            }
            else if (value < 60)
            {
                str = string.Concat(" педесет и ", ConvertDigitMacedonian(value - 50));
            }
            else if (value == 60)
            {
                str = " шеесет";
            }
            else if (value < 70)
            {
                str = string.Concat(" шеесет и ", ConvertDigitMacedonian(value - 60));
            }
            else if (value == 70)
            {
                str = " седумдесет";
            }
            else if (value < 80)
            {
                str = string.Concat(" седумдесет и ", ConvertDigitMacedonian(value - 70));
            }
            else if (value == 80)
            {
                str = " осумдесет";
            }
            else if (value < 90)
            {
                str = string.Concat(" осумдесет и ", ConvertDigitMacedonian(value - 80));
            }
            else if (value == 90)
            {
                str = " деведесет";
            }
            else if (value < 100)
            {
                str = string.Concat(" деведесет и ", ConvertDigitMacedonian(value - 90));
            }
            else if (value == 100)
            {
                str = " сто";
            }
            else if (value < 200)
            {
                str = string.Concat(" сто", ConvertDigitMacedonian(value - 100));
            }
            else if (value == 200)
            {
                str = " двесте";
            }
            else if (value < 300)
            {
                str = string.Concat(" двесте ", ConvertDigitMacedonian(value - 200));
            }
            else if (value == 300)
            {
                str = " триста";
            }
            else if (value < 400)
            {
                str = string.Concat(" триста ", ConvertDigitMacedonian(value - 300));
            }
            else if (value == 400 || value == 500 || value == 600 || value == 700 || value == 800 || value == 900)
            {
                str = string.Concat(ConvertDigitMacedonian(value / 100), "стотини");
            }
            else if (value < 1000)
            {
                str = string.Format("{0}{1}", ConvertDigitMacedonian(value / 100 * 100), ConvertDigitMacedonian(value % 100));
            }
            else if (value == 1000)
            {
                str = " илјада";
            }
            else if (value < 2000)
            {
                str = string.Concat(" илјада ", ConvertDigitMacedonian(value % 1000));
            }
            else if (value < 1000000)
            {
                str = string.Concat(ConvertDigitMacedonian(value / 1000), " илјади");
                if (value % 1000 > 0)
                {
                    str = string.Concat(str, " и ", ConvertDigitMacedonian(value % 1000));
                }
            }
            else if (value == 1000000)
            {
                str = " милион";
            }
            else if (value < 2000000)
            {
                str = string.Concat(" милион и ", ConvertDigitMacedonian(value % 1000000));
            }
            else if (value < 1000000000)
            {
                str = string.Concat(ConvertDigitMacedonian(value / 1000000), " милиони");
                if (value - value / 1000000 * 1000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitMacedonian(value - value / 1000000 * 1000000));
                }
            }
            else if (value == 1000000000)
            {
                str = " милијарда";
            }
            else if (value < 2000000000)
            {
                str = string.Concat(" милијарда и ", ConvertDigitMacedonian(value % 1000000000));
            }
            else if (value < 1000000000000)
            {
                str = string.Concat(ConvertDigitMacedonian(value / 1000000000), " милијарди");
                if (value - value / 1000000000 * 1000000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitMacedonian(value - value / 1000000000 * 1000000000));
                }
            }
            else if (value == 1000000000000)
            {
                str = " трилион";
            }
            else if (value < 2000000000000)
            {
                str = string.Concat(" трилион и ", ConvertDigitMacedonian(value % 1000000000000));
            }
            else if (value < 1000000000000000)
            {
                str = string.Concat(ConvertDigitMacedonian(value / 1000000000000), " трилиони");
                if (value - value / 1000000000000 * 1000000000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitMacedonian(value - value / 1000000000000 * 1000000000000));
                }
            }

            return str;
        }



        /// <summary>
        /// Spells numbers in macedonian language.
        /// </summary>
        /// <param name="Value"></param>
        /// <returns>string</returns>
        private static string SpellNumberInMacedonian(double Value)
        {
            Int64 num = (Int64)Value;
            string str = Value.ToString("0.00#");
            char[] chrArray = new char[] { ',' };
            string str1 = str.Split(chrArray)[1];
            Int64 num1 = Int64.Parse(str1);
            if (num1 == 0)
            {
                return ConvertDigitMacedonian(num);
            }
            return string.Format("{0} точка { 1} ", ConvertDigitMacedonian(num), ConvertDigitMacedonian(num1));
        }
        #endregion





        #region English numbers
        /// <summary>
        /// Converts digits to english words.
        /// </summary>
        /// <param name="value">int64</param>
        /// <returns>string</returns>
        private static string ConvertDigitEnglish(Int64 value)
        {
            string str = String.Empty;
            if (value < 0)
            {
                return string.Concat("minus ", ConvertDigitEnglish(Math.Abs(value)));
            }
            if (value == 0)
            {
                str = "zero";
            }
            else if (value == 1)
            {
                str = "one";
            }
            else if (value == 2)
            {
                str = "two";
            }
            else if (value == 3)
            {
                str = "three";
            }
            else if (value == 4)
            {
                str = "four";
            }
            else if (value == 5)
            {
                str = "five";
            }
            else if (value == 6)
            {
                str = "six";
            }
            else if (value == 7)
            {
                str = "seven";
            }
            else if (value == 8)
            {
                str = "eight";
            }
            else if (value == 9)
            {
                str = "nine";
            }
            else if (value == 10)
            {
                str = "ten";
            }
            else if (value == 11)
            {
                str = "eleven";
            }
            else if (value == 12)
            {
                str = "twelve";
            }
            else if (value == 13)
            {
                str = "thirteen";
            }
            else if (value == 14)
            {
                str = "fourteen";
            }
            else if (value == 15)
            {
                str = "fifteen";
            }
            else if (value == 16)
            {
                str = "sixteen";
            }
            else if (value == 17)
            {
                str = "seventeen";
            }
            else if (value == 18)
            {
                str = "eighteen";
            }
            else if (value == 19)
            {
                str = "nineteen";
            }
            else if (value < 20)
            {
                str = string.Concat(" twenty", ConvertDigitEnglish(value - 10));
            }
            else if (value == 20)
            {
                str = " twenty";
            }
            else if (value < 30)
            {
                str = string.Concat(" twenty", ConvertDigitEnglish(value - 20));
            }
            else if (value == 30)
            {
                str = " thirty";
            }
            else if (value == 40)
            {
                str = " forty";
            }
            else if (value == 50)
            {
                str = " fifty";
            }
            else if (value == 60)
            {
                str = " sixty";
            }
            else if (value == 70)
            {
                str = " seventy";
            }
            else if (value == 80)
            {
                str = " eighty";
            }
            else if (value == 90)
            {
                str = " ninety";
            }
            else if (value < 100)
            {
                Int64 num = value % 10;
                str = string.Format("{0}-{1}", ConvertDigitEnglish(value / 10 * 10), (num == 1 ? "one" : ConvertDigitEnglish(value % 10)));
            }
            else if (value == 100)
            {
                str = " one hundred";
            }
            else if (value < 200)
            {
                str = string.Concat(" one hundred and ", ConvertDigitEnglish(value - 100));
            }
            else if (value == 200 || value == 300 || value == 400 || value == 600 || value == 800 || value == 500 || value == 700 || value == 900)
            {
                str = string.Concat(ConvertDigitEnglish(value / 100), " hundred");
            }
            else if (value < 1000)
            {
                str = string.Format("{0} {1}", ConvertDigitEnglish(value / 100 * 100), ConvertDigitEnglish(value % 100));
            }
            else if (value == 1000)
            {
                str = " one thousand";
            }
            else if (value < 2000)
            {
                str = string.Concat(" one thousand ", ConvertDigitEnglish(value % 1000));
            }
            else if (value < 1000000)
            {
                str = string.Concat(ConvertDigitEnglish(value / 1000), " thousand");
                if (value % 1000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitEnglish(value % 1000));
                }
            }
            else if (value == 1000000)
            {
                str = " one million";
            }
            else if (value < 2000000)
            {
                str = string.Concat(" one million ", ConvertDigitEnglish(value % 1000000));
            }
            else if (value < 1000000000)
            {
                str = string.Concat(ConvertDigitEnglish(value / 1000000), " millions");
                if (value - value / 1000000 * 1000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitEnglish(value - value / 1000000 * 1000000));
                }
            }
            else if (value == 1000000000)
            {
                str = " one billion";
            }
            else if (value < 2000000000)
            {
                str = string.Concat("one billion ", ConvertDigitEnglish(value % 1000000000));
            }
            else if (value < 1000000000000)
            {
                str = string.Concat(ConvertDigitEnglish(value / 1000000000), " billions");
                if (value - value / 1000000000 * 1000000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitEnglish(value - value / 1000000000 * 1000000000));
                }
            }
            else if (value == 1000000000000)
            {
                str = " one trillion";
            }
            else if (value < 2000000000000)
            {
                str = string.Concat(" one trillion ", ConvertDigitEnglish(value % 1000000000000));
            }
            else if (value < 1000000000000000)
            {
                str = string.Concat(ConvertDigitEnglish(value / 1000000000000), " trillions");
                if (value - value / 1000000000000 * 1000000000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitEnglish(value - value / 1000000000000 * 1000000000000));
                }
            }

            return str;
        }


        /// <summary>
        /// Spells numbers in english language.
        /// </summary>
        /// <param name="Value"></param>
        /// <returns>string</returns>
        private static string SpellNumberInEnglish(double Value)
        {
            Int64 num = (Int64)Value;
            string str = Value.ToString("0.00#");
            char[] chrArray = new char[] { ',' };
            string str1 = str.Split(chrArray)[1];
            Int64 num1 = Int64.Parse(str1);
            if (num1 == 0)
            {
                return ConvertDigitEnglish(num);
            }
            return string.Format("{0} dot {1} ", ConvertDigitEnglish(num), ConvertDigitEnglish(num1));
        }
        #endregion









        #region Afrikaans numbers
        /// <summary>
        /// Converts digits to afrikaans words.
        /// </summary>
        /// <param name="value">int64</param>
        /// <returns>string</returns>
        private static string ConvertDigitAfrikaans(Int64 value)
        {
            string str = String.Empty;
            if (value < 0)
            {
                return string.Concat("minus ", ConvertDigitAfrikaans(Math.Abs(value)));
            }
            if (value == 0)
            {
                str = "nul";
            }
            else if (value == 1)
            {
                str = "een";
            }
            else if (value == 2)
            {
                str = "twee";
            }
            else if (value == 3)
            {
                str = "drie";
            }
            else if (value == 4)
            {
                str = "vier";
            }
            else if (value == 5)
            {
                str = "vyf";
            }
            else if (value == 6)
            {
                str = "ses";
            }
            else if (value == 7)
            {
                str = "sewe";
            }
            else if (value == 8)
            {
                str = "agt";
            }
            else if (value == 9)
            {
                str = "nege";
            }
            else if (value == 10)
            {
                str = "tien";
            }
            else if (value == 11)
            {
                str = "elf";
            }
            else if (value == 12)
            {
                str = "twaalf";
            }
            else if (value == 13)
            {
                str = "dertien";
            }
            else if (value == 14)
            {
                str = "veertien";
            }
            else if (value == 15)
            {
                str = "vyftien";
            }
            else if (value == 16)
            {
                str = "sestien";
            }
            else if (value == 17)
            {
                str = "sewentien";
            }
            else if (value == 18)
            {
                str = "agtien";
            }
            else if (value == 19)
            {
                str = "negentien";
            }
            else if (value == 20)
            {
                str = "twintig";
            }
            else if (value < 30)
            {
                str = string.Concat(ConvertDigitAfrikaans(value - 20), " en twintig");
            }
            else if (value == 30)
            {
                str = " dertig";
            }
            else if (value < 40)
            {
                str = string.Concat(ConvertDigitAfrikaans(value - 30), " en dertig");
            }
            else if (value == 40)
            {
                str = " veertig";
            }
            else if (value < 50)
            {
                str = string.Concat(ConvertDigitAfrikaans(value - 40), " en veertig");
            }
            else if (value == 50)
            {
                str = " vyftig";
            }
            else if (value < 60)
            {
                str = string.Concat(ConvertDigitAfrikaans(value - 50), " en vyftig");
            }
            else if (value == 60)
            {
                str = " sestig";
            }
            else if (value < 70)
            {
                str = string.Concat(ConvertDigitAfrikaans(value - 60), " en sestig");
            }
            else if (value == 70)
            {
                str = " sewentig";
            }
            else if (value < 80)
            {
                str = string.Concat(ConvertDigitAfrikaans(value - 70), " en sewentig");
            }
            else if (value == 80)
            {
                str = " tagtig";
            }
            else if (value < 90)
            {
                str = string.Concat(ConvertDigitAfrikaans(value - 80), " en tagtig");
            }
            else if (value == 90)
            {
                str = " negentig";
            }
            else if (value < 100)
            {
                str = string.Concat(ConvertDigitAfrikaans(value - 90), " en negentig");
            }
            else if (value == 100)
            {
                str = " een honderd";
            }
            else if (value < 200)
            {
                str = string.Concat(" een honderd ", ConvertDigitAfrikaans(value - 100));
            }
            else if (value == 300 || value == 400 || value == 500 || value == 600 || value == 700 || value == 800 || value == 900)
            {
                str = string.Concat(ConvertDigitAfrikaans(value / 100), " honderd");
            }
            else if (value < 1000)
            {
                str = string.Format("{0} en {1}", ConvertDigitAfrikaans(value / 100 * 100), ConvertDigitAfrikaans(value % 100));
            }
            else if (value == 1000)
            {
                str = " een duisend";
            }
            else if (value < 2000)
            {
                str = string.Concat("een duisend ", ConvertDigitAfrikaans(value % 1000));
            }
            else if (value < 1000000)
            {
                str = string.Concat(ConvertDigitAfrikaans(value / 1000), " duisend en");
                if (value % 1000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitAfrikaans(value % 1000));
                }
            }
            else if (value == 1000000)
            {
                str = " een miljoen";
            }
            else if (value < 2000000)
            {
                str = string.Concat("een miljoen ", ConvertDigitAfrikaans(value % 1000000));
            }
            else if (value < 1000000000)
            {
                str = string.Concat(ConvertDigitAfrikaans(value / 1000000), " miljoen");
                if (value - value / 1000000 * 1000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitAfrikaans(value - value / 1000000 * 1000000));
                }
            }
            else if (value == 1000000000)
            {
                str = " een miljard";
            }
            else if (value < 2000000000)
            {
                str = string.Concat("een miljard en ", ConvertDigitAfrikaans(value % 1000000000));
            }
            else if (value < 1000000000000)
            {
                str = string.Concat(ConvertDigitAfrikaans(value / 1000000000), " miljard");
                if (value - value / 1000000000 * 1000000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitAfrikaans(value - value / 1000000000 * 1000000000));
                }
            }
            else if (value == 1000000000000)
            {
                str = " een biljoen";
            }
            else if (value < 2000000000000)
            {
                str = string.Concat("een biljoen en ", ConvertDigitAfrikaans(value % 1000000000000));
            }
            else if (value < 1000000000000000)
            {
                str = string.Concat(ConvertDigitAfrikaans(value / 1000000000000), " biljoen");
                if (value - value / 1000000000000 * 1000000000000 > 0)
                {
                    str = string.Concat(str, " ", ConvertDigitAfrikaans(value - value / 1000000000000 * 1000000000000));
                }
            }

            return str;
        }


        /// <summary>
        /// Spells numbers in afrikaans language.
        /// </summary>
        /// <param name="Value"></param>
        /// <returns>string</returns>
        private static string SpellNumberInAfrikaans(double Value)
        {
            Int64 num = (Int64)Value;
            string str = Value.ToString("0.00#");
            char[] chrArray = new char[] { ',' };
            string str1 = str.Split(chrArray)[1];
            Int64 num1 = Int64.Parse(str1);
            if (num1 == 0)
            {
                return ConvertDigitAfrikaans(num);
            }
            return string.Format("{0} punt {1} ", ConvertDigitAfrikaans(num), ConvertDigitAfrikaans(num1));
        }
        #endregion





The above code takes into account the different languages numbers spelling rules. The precision of decimal point digits is 2 digits after the point.