How to detect page language

  1. Avatar of Mukesh

    Hi I need to detect page language dynamically on a pure CMS page, please suggest how to do that.

  2. Avatar of Mantas

    Hello Mukesh,

    You can add server side widget which is capable of resolving language dynamically. There are several ways to do that.

    1. You can retrieve from RenderWidgetViewModel property model.Page.LanguageCode. This is easiest and most efficient.

    2. In some cases your widget may be placed inside a master page, consequently LanguageCode will not be available. Therefore you will have to query API for page to get more details.

    Code sample would look like this:

        GetPageResponse response = null;
        using (var api = ApiFactory.Create())
            var pageRequest = new GetPageRequest { PageId = model.Page.Id };
            response = api.Pages.Page.Get(pageRequest);
        var languageCode = response.Data.LanguageCode;

    So if the page is a not a masterpage, languageCode will have a valid value.

    Hope this helps, let me know if you have any questions

  3. Avatar of Darsana R

    Thanks , its helped me too

* Mandatory
* Mandatory
* Mandatory

Verify that you are human