27.06.2009, 10:05 | #1 |
Участник
|
mscrm4ever: CRM 4.0 Creating a JS Resource Manager
Источник: http://mscrm4ever.blogspot.com/2009/...e-manager.html
============== The purpose of this post is to present a simple and effective way of handling multi-lingual text resources on the client (CRM) Form. In most projects an application is built to address a single language. Knowing that from the get go simplifies the way developers weave (hard code) the application messages into each entity form. Let’s assume, for example, that you need to validate that the account number starts with the letters “ACT ”. Your code might look like the following example: if (/^ACT\s{1}/.test(crmForm.accountnumber.DataValue) == false) { alert(”Account number must begin with ACT ”); } This is a very simple and strait forward way to present messages to the user. However since CRM is a multi-lingual application using this approach is far from being a best practice. The reason is that your client might decide (eventually) to add another language to the system and once he does that you must rewrite you application to support the new language. Assuming you have a small amount of messages you might consider changing your code as follows: if (/^ACT\s{1}/.test(crmForm.accountnumber.DataValue) == false) { if (USER_LANGUAGE_CODE == 1033) //English United States { alert(”Account number must begin with ACT ”); } else if (USER_LANGUAGE_CODE == 1043) //Dutch { alert(”Rekeningnummer moet beginnen met ACT ”); } } Now, as long as the application stays small this solution should hold. However, applications tend to grow over time and from a certain point the amount of messages will be too overwhelming to manage in this manner. Another reason why this approach is a bad practice is that is obligates or ties the client to an ever lasting development phase. The best approach is to shift the responsibility of handling multi-lingual tasks to the client and the best way to do that is to create a resource manager that enables you to support multi-lingual messages from your first line of code. So how do we shift responsibility of translating our application messages to the client? The simplest approach is to create a new text attribute for each message that you need to display. The text attribute display name can hold the message it self. For example: New Attribute: new_msginvalidaccountnumber Display Name: The account number must begin with “ACT “ Searchable: No Required:No Now, put the new attribute on the CRM form under a new tab called Labels and hide it when the form loads. E.g. function OnCrmPageLoad() { document.all.tab4Tab.style.display = “none” //assuming that the fifth tab is the Labels tab. } OnCrmPageLoad(); Now, let’s transform the above code so it would support any language /* --< Resource Manager >-- */ ResourceManager = function() { var rm = this; rm.GetString = function( resId ) { var resource = document.getElementById( resId ); if ( !resource ) { /* Show missing label */ return "[" + resId + "]"; } return crmForm.GetLabel( resource ); } } /* Create an instance of Resource Manager */ RM = new ResourceManager(); if (/^ACT\s{1}/.test(crmForm.accountnumber.DataValue) == false) { alert(RM.GetString(“new_msginvalidaccountnumber”)); } Integrate the resource manager to each entity onload event. Good luck… Источник: http://mscrm4ever.blogspot.com/2009/...e-manager.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
|