Forum Discussion
Hi iftomkins,
From your recent posts, it seems that you are building something similar to one of my recent projects: a language selection bar, which allows user to automatically switch to another language by a single click
Just to share what I did,
1) create an endpoint which can update user's profile language and expose itself as JSON.
<#assign result_result = "error" /> <#assign lang = http.request.parameters.name.get("lang", "")?trim /> <#if user.registered && lang?? > <#assign update_lang_setting = rest("/users/self/profiles/name/language/set?value=${lang}") /> <#if update_lang_setting.@status == 'success'> <#assign result_result = "success" /> </#if> </#if> {"response":"${result_result}"}
2) create a component, which calls that endpoint and refreshes the page when user clicks a particular language tab.
LITHIUM.jQuery.ajax({ type: "GET", url: "/plugins/custom/apac/apac/custom.apac.switch_language_edpt?lang=" + new_lang_code, dataType: "json", success: function (data) { if(data.response == "success") { window.location.reload(); } else { ......... } },
The output is like
btw: for anonymous user, you has no user profile to update, you may just need to add to load http://<your current URL>?profile.language=<new language code>
Will definitely leverage this. Thanks!
These endpoints and macros are areas I've never worked with before. To everyone that has replied, thanks for the help!
Doug
Related Content
- 2 months ago
- 12 months ago
- 10 months ago
- 2 years ago