Search code examples
c#resourcesresx

C# Replace Resource File Values


I'm not sure how to ask this question, but hopefully someone will understand and please feel free to correct my lack of terminology.

I'm using resource files to display the website in various languages. There's a section in a sentence that is driven by data from a DB, which we have a method for, and grabs it's resource from a local resource file.

Below is what our default.aspx file looks like:

<html>
    <body>
        <h1>Hello,</h1>
        <p><asp:Localize runat="server" Text="<%$ Resources: PersonalAttentionParagraph %>" /></p>
    </body>
</html>

The local resource file contains:

...
<data name="PersonalAttentionParagraph" xml:space="preserve">
    <value>Blah... 14:1 ...more blah!.</value>
</data>
...

That 14:1 value needs to come from a function:

string GetValue(){
    return "14:1";
}

Question: How do you properly create a replace functionality calling a resource file in this manner?

I was thinking of replacing the Resource file value 14:1 with @@VALUE@@ and then calling a Replace() on it, but I'm not sure if that's the correct way of doing it.

Thank you.


Solution

  • It's fairly common to put "blah... {0} .. more blah" in the resource file. When you use it, just use string.format(yourResourceString,someComputedValue.ToString()).