views:

35

answers:

1

I am trying to determine if it is possible to add a concatenated string to one of my local .resx files. This example should clarify:

Let's say I have a simple ASP.NET webpage composed of (1) a label whose text is an important keyword (2) an input with required field validation and (3) a button that causes validation to occur:

(lblMyInput)
(txtMyInput)
(rfvMyInput)
(btnSubmit)

Now, inside the resource file for this page, we want to localize the strings for the page's controls. However, for our error message, we want to use the literal name of the input's label. This is were my question is.

PSEUDOCODE: myPage.resx

(1) lblMyInput.Text = "Name"
(2) rfvMyInput.ErrorMessage = "The " + lblMyInput.Text + " field may not be left blank."
(3) btnSubmit.Text = "Submit/Validate"

Is there any way to pull off this type of concatenation of one resource file's string into another string within the same file?

Thanks!

+3  A: 

One way to do it would be to have your two resx strings and work thusly:

Resource1: "Hello, this is a {0}" Resource2: "Cookie"

And use the string parser to plop Resource2 into Resource1. A standard solution but not a very good one, as it requires the developer to know about the {0}. It also leads to localization issues if it ever goes off to translation.. not all languages have words in the same order as English.

Stefan Valianu
+1, this is how I do it. Just a note though, if he sends along a small explanation to the translation company that the {0} is basically a placeholder (and let them know what the placeholder is for), they should be able to work around it fairly easily.
Brandon
Haha, I can't believe I didn't think of that. Good point.
Stefan Valianu
Could you be more specific as to how the string parser is used? Do you handle this in the codebehind page or from the .aspx page? Or is this an inherent behavior caused by the sequential naming scheme of "Resource1...Resource2"?
Buffalo