{"id":13140,"date":"2018-10-17T22:50:13","date_gmt":"2018-10-17T17:20:13","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=13140"},"modified":"2018-10-17T22:50:13","modified_gmt":"2018-10-17T17:20:13","slug":"multiple-language-options-on-a-single-web-page-in-microsoft-portal","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2018\/10\/multiple-language-options-on-a-single-web-page-in-microsoft-portal\/","title":{"rendered":"Multiple language options on a single web page in Microsoft Portal"},"content":{"rendered":"<h2><strong>Introduction:<\/strong><\/h2>\n<p>Recently we had a business requirement to use a localization (Multiple language options) on a single page i.e. not for the whole portal website.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-13141 \" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/10\/1Multiple-language-options-on-a-single-web-page-in-Microsoft-Portal1.png\" alt=\"1Multiple language options on a single web page in Microsoft Portal\" width=\"820\" height=\"371\" \/><\/p>\n<p style=\"text-align: justify;\">But we don\u2019t want to use out of box localization concept since it applies to whole portal website as shown in above screenshot.<\/p>\n<p style=\"text-align: justify;\">So after some research and play around we found the solution as follows:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-13143 \" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/10\/2Multiple-language-options-on-a-single-web-page-in-Microsoft-Portal1.png\" alt=\"2Multiple language options on a single web page in Microsoft Portal\" width=\"820\" height=\"415\" \/><\/p>\n<p style=\"text-align: justify;\">Steps to achieve the localization on single page:<\/p>\n<p style=\"text-align: justify;\"><strong>1<\/strong>. Firstly we will create a \u201cMulitpleLanguage\u201d record (it can be anything) in Site Settings entity.<\/p>\n<p style=\"text-align: justify;\">While creating Site setting record the <strong>Value<\/strong> field will contain different languages with \u201d,\u201d separated and <strong>Description<\/strong> field will contains a translation json for each language as shown in the below screenshot.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-13144 \" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/10\/3Multiple-language-options-on-a-single-web-page-in-Microsoft-Portal.png\" alt=\"3Multiple language options on a single web page in Microsoft Portal\" width=\"823\" height=\"521\" \/><\/p>\n<p><strong>2<\/strong>. Now on the WebPage entity where we want to call the multiple language option we will have a Blank Page page template that calls Blank page web template.<\/p>\n<p>Here we have created a Time entry web page that calls Blank Page page template and that page template calls Blank Page web Template that contains following code:<\/p>\n<p>Time Entry(Web Page) =&gt; Blank\u00a0 Page(Page Template) =&gt; Blank Page(Web Template)<\/p>\n<pre class=\"lang:default decode:true \">{% fetchxml multipleLanguageQuery %}\n    &lt;fetch version=\"1.0\" output- format=\"xml-platform\" mapping= \"logical\" distinct= \"false\" &gt;\n    &lt;entity name=\"adx_sitesetting\" &gt;\n    &lt;attribute name=\"adx_name\" \/&gt;\n    &lt;attribute name=\"adx_value\" \/&gt;\n    &lt;attribute name=\"adx_description\" \/&gt;\n    &lt;filter type=\"and\" &gt;\n    &lt;condition attribute=\"adx_name\" operator= \"eq\" value= \"MulitpleLanguage\" \/&gt;\n    &lt;\/filter&gt;\n    &lt; \/entity&gt;\n    &lt; \/fetch&gt;\n{% endfetchxml %}\n\n{% assign multipleLanguages = multipleLanguageQuery.results.entities %}\n{% assign languages = \"\" %}\n{% assign translations = \"\" %}\n\n&lt;div class=\"container\" style= \"padding-top:25px;\" &gt;\n    {% editable page 'adx_copy' %}\n\n    {% if multipleLanguages.size &gt; 0 %}\n        &lt;div style=\"text-align: right; padding-top:25px;\" &gt;\n            &lt;select id=\"selectedlanguage\" &gt;\n                {% for multipleLanguage in multipleLanguages %}\n                    {% assign languages = multipleLanguage.adx_value | split: \",\" %}\n                    {% assign translations = multipleLanguage.adx_description %}\n                    {% for language in languages %}\n                        &lt;option value={ { language } }&gt;{{language }}&lt;\/option&gt;\n                    {% endfor %}\n                {% endfor %}\n            &lt;\/select&gt;\n            &lt; label id= \"jsonlanguage\" style= \"display:none;\" &gt; {{translations }}&lt;\/label&gt;\n        &lt; \/div&gt;\n    {% endif %}\n    {% if page.adx_entityform %}\n        {% entityform id: page.adx_entityform.id %}\n    {% endif %}\n&lt;\/div&gt;\n<\/pre>\n<p><strong>\u00a03<\/strong>. On \u201cTime Entry\u201d record of Web Page entity we have an advanced tab that contains a custom javascript which will contain following javascript code that will change the single form language based on the language selected in the dropdown.<\/p>\n<pre class=\"lang:default decode:true\">window.onload = function () {\n    \n    var selectedlanguage = localStorage.getItem(\"selectedLanguage\");\n    if (selectedlanguage != \"\") {\n        $(\"#selectedlanguage\").val(selectedlanguage).change();\n    }\n    \n};\n\n$(\"#selectedlanguage\").change(function () {\n     var selectedlanguage = $(\"#selectedlanguage\").val();\n    \/\/ Check browser support\n    if (typeof (Storage) !== \"undefined\") {\n        \/\/ Store\n        localStorage.setItem(\"selectedLanguage\", selectedlanguage);\n    }\n    var jsonObject = $.parseJSON($('#jsonlanguage')[0].innerText);\n    var jsonLanguageFields = jsonObject[selectedlanguage].Fields;\n    var jsonLanguageOptionSets = jsonObject[selectedlanguage].OptionSet;\n    var jsonLanguageButtons = jsonObject[selectedlanguage].Buttons;\n    if (Object.keys(jsonLanguageFields).length &gt; 0) {\n        $.each(jsonLanguageFields, function (key, value) {\n            document.getElementById(key).innerText = value;\n        });\n    }\n    if (Object.keys(jsonLanguageOptionSets).length &gt; 0) {\n        var htmlOptionSet = $(\"option\");\n        $.each(jsonLanguageOptionSets, function (key, value) {\n            for (var i = 0; i &lt; htmlOptionSet.length; i++) {\n                if (htmlOptionSet[i].innerText == key) {\n                    htmlOptionSet[i].innerText = value;\n                }\n            }\n        });\n    }\n\n    if (Object.keys(jsonLanguageButtons).length &gt; 0) {\n        var htmlButton = $(\":button\");\n        $.each(jsonLanguageButtons, function (key, value) {\n            for (var i = 0; i &lt; htmlButton.length; i++) {\n                if (htmlButton[i].value == key) {\n                    htmlButton[i].value = value;\n                }\n            }\n        })\n    }\n});<\/pre>\n<p><strong>4<\/strong>. On change of the language in dropdown we have following translated form with the optionset value also translated in it as shown in below screenshot.<\/p>\n<p>English translated single page<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-13145 \" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/10\/4Multiple-language-options-on-a-single-web-page-in-Microsoft-Portal1.png\" alt=\"4Multiple language options on a single web page in Microsoft Portal\" width=\"824\" height=\"417\" \/>Spanish translated single page<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-13146 \" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/10\/5Multiple-language-options-on-a-single-web-page-in-Microsoft-Portal1.png\" alt=\"Multiple language options on a single web page in Microsoft Portal\" width=\"820\" height=\"404\" \/><\/p>\n<h2><strong>Conclusion<\/strong>:<\/h2>\n<p>By keep translation in JSON format in Site Setting record we can achieve the localization On single page.<\/p>\n<p><a href=\"https:\/\/www.maplytics.com\/features\/maplytics-multi-language-mapping-app-dynamics-365\/\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter  wp-image-11613\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/04\/Generate-Your-Own-New-Leads-Now-Within-Dynamics-365-CRM-with-Maplytics-11.png\" alt=\"Generate Your Own New Leads Now Within Dynamics 365 CRM with Maplytics\" width=\"973\" height=\"243\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: Recently we had a business requirement to use a localization (Multiple language options) on a single page i.e. not for the whole portal website. But we don\u2019t want to use out of box localization concept since it applies to whole portal website as shown in above screenshot. So after some research and play around\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2018\/10\/multiple-language-options-on-a-single-web-page-in-microsoft-portal\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":13147,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[16,18,19,37],"tags":[1162,1235],"class_list":["post-13140","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365","category-dynamics-365-v9-2","category-dynamics-crm","category-microsoft-portals","tag-microsoft-portal","tag-multiple-language-options-microsoft-portal"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/13140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=13140"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/13140\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/13147"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=13140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=13140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=13140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}