views:

162

answers:

1

I'm creating WebResources.resx file with several string messages I'd like to categorize:

Signup_Status_Inactive Signup_Status_Reserved etc...

Since it's just an XML file in the background, is it possible to create parent/child relationships so I don't have to prefix related strings and follow a better dot notation?

To get around this I can create a class with some properties accessed through proper dot notation, ie StatusMessages.Signup.Inactive - but that's just extra work.

Is there only one level to the string component of the .resx files?

Additionally, how do you output session variables as a part of the resx value - ie: "Your Card #" + HttpContext.Current.Session["ReservedCardNum"] + " has been reserved for you."

Thanks.

+1  A: 

All the keys in a .resx file are single level, however there is nothing stopping you from using your own XML format, provided you write the code to read it and any tools that are needed to maintain it.


To output session variables, I would use String.Format()

Normally you would write

String.Format(“"Your Card #{0}  has been reserved for you.", 
              HttpContext.Current.Session["ReservedCardNum"])

So just instead just use

String.Format(stringLookedFromResouceFile, 
              HttpContext.Current.Session["ReservedCardNum"])

And put the “{0}” in the translated string, that way the translators can change the order of the words if needed.


Think about how you will communicate to the translators what the placeholders, If the translators are using a resource editor that shows the comment field, you could add comments like “{0} = username”

You will also have to somehow check that the translators don’t mess up the place holders, I have seen translators change “{0}” to “(0)” as they “think the other sort of brackets look better” etc! or delete one of the brackens so the string format is no longer valid.

see How to validate format string

Ian Ringrose
+1. Also if using the resource editor use the Comments field to document what is going into each of the replacement fields; context (such as "personal name" or "item count"), and data type are really useful for translators.
devstuff