Search code examples
c#.netconfigmultilingualresx

Multilanguage supported programme codding methods in c#


I want to create a program that support multilanguage in C#. But I need that the program should take the content of languages by using a text file(or .resx file, config file). I need that when I changed the meaning of one word from a text file, I must see the changes in the program without compiling .exe file. How can I achieve this? Thank you.


Solution

  • What you want is called [Internationalization (I18N)][1].

    You should take a look into this documentation

    Also here's an example taken from this post:

     public class HelloWorld
    {
        public CultureInfo CultureInfo { get; private set; }
    
        public HelloWorld()
        {
            CultureInfo = CultureInfo.CurrentCulture;
        }
    
        public HelloWorld(string culture)
        {
            CultureInfo = CultureInfo.GetCultureInfo(culture);
        }
    
        public string SayHelloWorld()
        {
            return Resources.ResourceManager.GetString("HelloWorld", CultureInfo);
        }
    }
    
    
    [TestFixture]
    public class HelloWorldFixture
    {
        HelloWorld helloWorld;
    
        [Test]
        public void Ctor_SetsCultureInfo_ToCurrentCultureForParameterlessCtor()
        {
            helloWorld = new HelloWorld();
            Assert.AreEqual(helloWorld.CultureInfo, CultureInfo.CurrentCulture,
                "Expected CultureInfo to be set as CurrentCulture");
        }
    
        [Test]
        public void Ctor_SetsCultureInfo_ToAustralianCulture()
        {
            helloWorld = new HelloWorld("en-AU");
            Assert.AreEqual(helloWorld.CultureInfo.Name, "en-AU",
                "Expected CultureInfo to be set to Australian culture");
        }
    
        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void Ctor_ThrowsException_InvalidCultureName()
        {
            helloWorld = new HelloWorld("Bogus");
        }
    
        [Test]
        public void SayHelloWorld_ReturnsFallbackResource_OnUndefinedResource()
        {
            helloWorld = new HelloWorld("en-JM");
            string result = helloWorld.SayHelloWorld();
            Assert.AreEqual("Hello, World.", result, "Expected fallback resource string to be used");
        }
    
        [Test]
        public void SayHelloWorld_ReturnsAustralianResource_OnAustralianResource()
        {
            helloWorld = new HelloWorld("en-AU");
            string result = helloWorld.SayHelloWorld();
            Assert.AreEqual("G'Day, World.", result, "Expected australian resource string to be used");
        }
    }