Skip to main content

Date localization in Adxstudio Portals.




     How to set language based  date format in Adx portal page.

     Custom date and time formats in a frontend are always a headache. Adx is trying to make our life better by giving us some OOB options and features.  They changes approach for portal date and time formats implementation and controls very often.

      This Adx article demonstrates how to manage formats programmatically but only in version 6.0.0013 and earlier. Till version 7.0.0019  Site Settings (DateTime/DateFormat, DateTime/TimeFormat, DateTime, DateTimeFormat) had been used to set body tag attributes with .Net custom and standard formats.  Since 7.0.0019 these Site Settings are still there but the momentjs  library is used to set up body tag attributes. It works great. Except makes you learn a new Java Script library to make it work the way you need. I don’t understand what’s wrong with .Net custom formats.
      Let's see how we can benefit from current functionality.
      Assume you have two web sites, French and English. Base datetime format is “EN-US” => “mm/dd/yyyy”. English web site has to follow base format and French needs to implement “dd/mm/yyyy” format. If you just set DateTime/DateFormat value equals ‘L’ it will do make both portals show dates in base format.

       The catch here in momentjs. This library formats dates based on language settings. And Portal lacks the setting of language for momentjs. Or I couldn’t find it L. Once it set to proper language the format meets your needs.

     You can easily set it yourself programmatically based on portal’s Language code. Place the code on Master or content page in script tags. Depend on scope you need it. 

   $(document).ready(function () {

 

            //set page date formats according to user language

            if (_languageCode == '1036') {

                moment.locale("en", null);

                moment.locale("fr");

            }

            else {

                moment.locale("fr", null);

                moment.locale("en");

            }

        });

       Adding the language parameter via Site Settings would be much faster and easier. I hope Adx (MS) will add such small but very useful Site Setting option before portal will be a part of Crm license. Or again they will change approach completely that’s more likely J.
      
        Update:
      
        The proposed solution is working for pages in Create mode only. Full issue description and a bug opened for Adx can be found here.

Comments

Most popular

Dynamics 365 online and Adx portal on-premise. Are they compatible?

Adxstudio Portal how to: Incremental (Sequential) Deployment and backup. Part I

Custom plugin exception output for crm form