I will try to explain the best way I can. I am not an experienced programmer.
I am using Visual Studio 2008 and C#
I have ressources files (resx) that contain strings and the equivalent in the language. For example I have:
English.resx
French.resx
With the following entries:
<data name="FileError" xml:space="preserve">
<value>There is a problem with the file : </value>
</data>
and
<data name="FileError" xml:space="preserve">
<value>Il y a un probleme avec le fichier : </value>
</data>
Then I have the following class:
static class Language
{
public static string FileError;
Language(string setLanguage)
{
switch (setLanguage)
{
case "ENGLISH":
FileError = English.FileError;
break;
case "FRENCH":
FileError = French.FileError;
break;
default:
break;
}
}
}
All of this so I can code the following way:
Language currentLanguage = Language((new ServiceConfiguration()).LanguageString)
...
try
{
File.AppendAllText("Writing...");
}
catch (Exception fileError)
{
Console.Write(currentLanguage.FileError + fileError.Message);
}
Here it doesn’t seem like much because there is only one message, but is there any better way I could do this ? It doesn’t seem to be too dynamic, and it looks like every time I will want to add a string I will have to recode it to multiple places, please advice a better way to do this.
Thank You.
.NET has built in localization functionality, so there’s no need to reinvent the wheel like you’re doing here. Check out the links below for more information:
http://www.codeproject.com/KB/dotnet/Localization.aspx
http://weblogs.asp.net/scottgu/archive/2006/05/30/ASP.NET-2.0-Localization-_2800_Video_2C00_-Whitepaper_2C00_-and-Database-Provider-Support_2900_.aspx
http://msdn.microsoft.com/en-us/library/c6zyy3s9.aspx