String.Format and translations

Vote:
 

Hi!


My problem is as follows: I have an .xml file (english.xml) that contains the following nodes,

 

<general>

      <storename>Wendie's</storename>

      <item1>French Fries</item1>

      <item2>Hamburger</item2>

      <item3>Soda</item3>

</general>

What i'd like to do is to have a welcome text when I arrive to my site that says: "Welcome to Wendie's. We have French Fries, Hamburger and Soda.  Help yourself!" I'd also like to have it globalized, which means this text has to be inserted into my english.xml, prefferably in a <welcometext>-node or something. How can I accomplish this? My first thought was to use String.Format like:


"Welcome to {0}. We have {1}, {2} and {3}. Help yourself!" and have the numbers represent different nodes in my xml, and thus making it globalized. But how can I accomplish this?

 

Thanks alot!

#59989
Jul 10, 2012 8:41
Vote:
 

If you use EPiServer lang-files (in the /lang/ folder) you can access the translations with LanguageManager.Instance.Translate("/general/item1").

#59992
Jul 10, 2012 9:57
Vote:
 

if you add

<general>

<welcometext>Welcome to {0}. We have {1}, {2} and {3}. Help yourself!</welcometext>

....

</general>

 

then I would expect this to work

 string message = string.Format(Translate("/general/welcometext"), Translate("/general/storename"), Translate("/general/item1"),Translate("/general/item2"), Translate("/general/item3"));

 

#59993
Jul 10, 2012 10:00
Vote:
 

Thanks alot! Final solution;

 

protected void Page_Load(object sender, EventArgs e)
        {
           SetWelcomeText();
        }
        
       
        public void SetWelcomeText() {
            string message = LanguageManager.Instance.Translate("/general/item1");
            string output = string.Format(LanguageManager.Instance.Translate("/general/infotext"), message);
            FancyMainContentTextLiteral.Text = output;
        }

 

ascx;

<asp:Literal runat="server" id="FancyMainContentTextLiteral" />

#59996
Jul 10, 2012 11:33
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.