If you are creating your own pipeline components and your site is international and you need more than the four languages that is out of the box German, French, Japanese and US English for Commerce Server then you need to create your own resource for other languages. How to create a new resource is what this post is all about.
Messagemanager is an object that handling the localization of messages inside your pipeline competents. When you unpack the CSharpSite you will get CommerceMessageManager.dll and four folders representing a language mentioned above.
What are these messages that Messagemanager use? The table below has the messages that Commerce Server uses internally. If you introducing a new language then you need to localize this table.
You need to take the localized messages and create an assembly. There are many methods the following help file link should help. Once you create an assembly then you need to add it into your bin folder, take care to create the language folder then add the assembly there.
Yes, but the help files do note that the messagemanager is obsolete (I wonder why then Commerce Server uses it? If you find the answer let me know :))?
If you have created your own messages and want to use it inside your custom pipeline components the following code will accomplish that.
// using message manager inside pipeline componentIMessageManager messageManager = null;IDictionary dict = (IDictionary) pContext; messageManager = (IMessageManager) dic["MessageManager"];object message = messageManager.GetMessage("your string key", language);
In order for the pipeline to use the specific language you must execute the Pipeline by passing the language code in the PipelineInfo object. If the language parameter is not specified, or is NULL, the message is returned for the message set identified by the DefaultLanguage property of the MessageManager object. This value is retrieved from the web.config under the messageManager element.
Once you have done all the above you will need to add the language in the web.config of your site. Why do I need to do this? We need to tell Commerce Server's Pipeline processor that we have a new language so when Commerce Server pipelines encounter an error they retrieve the message correctly.
<messageManager> <cultures default="en-US" baseName="CommerceMessageManager" assembly="CommerceMessageManager"> <culture id="en-US"/> <culture id="fr-fr"/> <culture id="ja-JP"/> <culture id="de-DE"/> <culture id="your new language"/> </cultures> <resources> <resource id="pur_badsku"/> <resource id="pur_badplacedprice"/> <resource id="pur_discount_changed"/> <resource id="pur_discount_removed"/> <resource id="pur_noitems"/> <resource id="pur_badshipping"/> <resource id="pur_badhandling"/> <resource id="pur_badtax"/> <resource id="pur_badcc"/> <resource id="pur_badpayment"/> <resource id="pur_badverify"/> <resource id="pur_out_of_stock"/> <resource id="unknown_shipping_method"/> </resources> </messageManager>
Will my custom component also work automagically? No, see the code above about messagemanager and notice that we are passing the language and since you set this value in the PipelineInfo object it will be accessible through the pipeline via the context (pdispContext) parameter.
OK, I think we are done now.