locked
create a multi languages website with xml file RRS feed

  • Question

  • User1864465085 posted

    hi

    i want to create a multi languages website with xml file

    actually i saw the yaf use this method and i also want to use it in my website with some difrent

    the xml file that use yaf look like this:

    <?xml version="1.0" encoding="utf-8"?>
    <Resources xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" language="English" code="en">
        <page name="HELP_INDEX">
    	<Resource tag="TITLE">YetAnotherForum.NET Help</Resource>
            <Resource tag="NAVIGATION">Navigation</Resource>
            <Resource tag="INDEX">Index</Resource>
    	<Resource tag="SUBTITLE">Forum Help</Resource>
    </page>
    </Resources>


     now i need to create a class that read the xml file and create some function that return the words like:

    Language.Title() will return the Title word as string

    can some one tell me how can get the information that i need or help me to write this class

    thanks

    Wednesday, December 29, 2010 1:33 PM

Answers

  • User-519136805 posted

    Hi ,

    Here is the code to fetch value from resource file :

    //Namespace reference
    using System;
    using System.Resources;
    
    
    #region ReadResourceFile
    /// <summary>
    /// method for reading a value from a resource file
    /// (.resx file)
    /// </summary>
    /// <param name="file">file to read from</param>
    /// <param name="key">key to get the value for</param>
    /// <returns>a string value</returns>
    public string ReadResourceValue(string file, string key)
    {
        //value for our return value
        string resourceValue = string.Empty;
        try
        {
            // specify your resource file name 
            string resourceFile = file;
            // get the path of your file
            string filePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
            // create a resource manager for reading from
            //the resx file
            ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager(resourceFile, filePath, null);
            // retrieve the value of the specified key
            resourceValue = resourceManager.GetString(key);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            resourceValue = string.Empty;
        }
        return resourceValue;
    }
    #endregion


    Now you can use this code to fetch key value , you just need to pass your xml filename & key , method will return value of the key.

    refere this link before using this code : here

    Hope this will help !!!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 1, 2011 12:38 AM

All replies

  • User-1887867400 posted

    Hi, no need to implement custom api for creating multilingual site. Check this tutorial:

    http://zeollar.cloudapp.net/Session/17

    or better:

     http://www.asp.net/general/videos/how-do-i-create-a-multi-lingual-site-with-localization

    Friday, December 31, 2010 3:37 AM
  • User1864465085 posted

    thanks for your replay

    the reson that i  use xml file is, i want to give the website owner that access if he/she need to create his/her owne language file can do that.

    but if i use resource file to do that the website owner have to install VS to create his/her owne resource file

    Friday, December 31, 2010 10:12 AM
  • User-519136805 posted

    Hi ,

    Here is the code to fetch value from resource file :

    //Namespace reference
    using System;
    using System.Resources;
    
    
    #region ReadResourceFile
    /// <summary>
    /// method for reading a value from a resource file
    /// (.resx file)
    /// </summary>
    /// <param name="file">file to read from</param>
    /// <param name="key">key to get the value for</param>
    /// <returns>a string value</returns>
    public string ReadResourceValue(string file, string key)
    {
        //value for our return value
        string resourceValue = string.Empty;
        try
        {
            // specify your resource file name 
            string resourceFile = file;
            // get the path of your file
            string filePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
            // create a resource manager for reading from
            //the resx file
            ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager(resourceFile, filePath, null);
            // retrieve the value of the specified key
            resourceValue = resourceManager.GetString(key);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            resourceValue = string.Empty;
        }
        return resourceValue;
    }
    #endregion


    Now you can use this code to fetch key value , you just need to pass your xml filename & key , method will return value of the key.

    refere this link before using this code : here

    Hope this will help !!!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 1, 2011 12:38 AM
  • User-1887867400 posted

    Hi, check this article. This article will use a database for storing the multilingual content but the idea is the same for the xml file too.


    http://www.codeproject.com/KB/aspnet/localization_websites.aspx

    Saturday, January 1, 2011 2:36 PM
  • User-1707956456 posted

    Hi Sandy and evryone,

    I was searching a lot for such technique to handle my website language resources. Actually I'm new with globalization and localization issues and currently reached to run my websites under different cultures using the RESX resources in VS.

    My request is if you may have time to explain the function you provided and tell me the required/supported  XML file with an example(s) for calling the keys values through my ASPs and code behind.

    thank you in advance for help.

    Wednesday, November 16, 2011 5:14 PM