How to add more countries

Feb 21, 2009 at 10:21 PM
Hi,

Is there a way to add more countries to the country list in the comments form?

Looking forward to some positive feedback.

Thanks,

Wasim
Coordinator
Feb 21, 2009 at 10:35 PM
Yes, you can add countries.  If you open up the CommentView.ascx.cs file in the User controls folder, you'll see an extra country is already being added,

// Add custom cultures
if (!dic.ContainsValue("bd"))
{
    dic.Add("Bangladesh", "bd");
    col.Add("Bangladesh");
}

You can just duplicate that code above (copy and paste) to add more countries.  If you have a flag image you want to show up when the country is selected, you can add a "PNG" image into the pics\flags folder.  The name of the PNG file should match the country code/abbreviation you add ... so in the case above, the flag image would be bd.png.
Feb 22, 2009 at 9:25 AM
Hi Ben,

You always seem to help me out. Thanks. I tried putting the country e.g Tanzania like this:

if (!dic.ContainsValue("tz"))
  {
   dic.Add("Tanzania", "tz");
   col.Add("Tanzania");
  }

However when I add a comment and choose Tanzania and mouse over the flag, it is showing "tz" on the tool tip instead of Tanzania. But when I add a comment with Bangladesh selected and mouse over the flag it shows "Bangladesh" correctly on the Tool Tip.
Although this is kinda small issue but some people might not know what tz stands for and so I would rather put the whole Country name instead of the code.

How do I do that. Is it possible? Am I missing something? Please advise.

Thanks,

Wasim
Coordinator
Feb 22, 2009 at 6:37 PM
Edited Feb 22, 2009 at 6:39 PM
I took a look at it.  The tooltip works correctly for Bangladesh because on your computer (and mine too) Bangladesh is a known country by Windows.  The country name for the tooltip comes from a lookup of the country name in Windows.  So that code in CommentView.ascx.cs which is adding Bangladesh to the dropdown list isn't actually doing anything because Bangladesh is already a known country.  Probably that code was put in there for someone who had a computer where Bangladesh was an unknown country.

There's at least 2 choices you have to get the tooltip to show up for Tanzania.

1. You can modify the code we added into CommentView.ascx.cs.  The new code would be:

if (!dic.ContainsValue("tz"))
  {
   dic.Add("Tanzania", "Tanzania");
   col.Add("Tanzania");
  }

If you do this, then you'll want to rename your tz.png file to Tanzania.png.

Doing this will store the commenter's country in the XML files/SQL database as "Tanzania" instead of the two letter country code (tz).  But this shouldn't be a problem since the country code in the XML file can be this long, and the country code in the SQL database can also be this long.

I can't think of any other part within BE that would be negatively affected by storing a country code this way.
 
2. Or you can modify the BE core file, CommentViewBase.cs, in the Web\Controls folder and recompile the BE core code.  In that file, you will find the code below.  The bolded part below is what you would want to add, and then recompile.

string FindCountry(string isoCode)
{
    if (isoCode.Equals("tz", StringComparison.OrdinalIgnoreCase))
        return "Tanzania";


    foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
    {
        RegionInfo ri = new RegionInfo(ci.Name);
        if (ri.TwoLetterISORegionName.Equals(isoCode, StringComparison.OrdinalIgnoreCase))
        {
            return ri.DisplayName;
        }
    }

    return isoCode;
}

Also, I noticed in the latest builds of BE, there's a flag in the pics\flags folder for Tanzania (tz.png).  If you don't already have a nice flag image for Tanzania, you could get that one ... downloadable on the Source Code tab above.
Feb 23, 2009 at 8:44 AM
Thanks Ben,

I think I will just have to go with your first approach.

btw I also noticed the flag in the pics\flags folder and in fact there are more flags added this time although they are not listed in the Country dropdown list. Hopefully in the next release they will be added.

Wasim