Try our conversational search powered by Generative AI!

String.Format and translations



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




      <item1>French Fries</item1>




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!

Jul 10, 2012 8:41

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

Jul 10, 2012 9:57

if you add


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




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"));


Jul 10, 2012 10:00

Thanks alot! Final solution;


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



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

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.