Setting Default Language via Category with jQuery

More
2 years 1 month ago - 2 years 1 month ago #84812 by iamrobert
Updated Code for Joomla 4 and FLEXIContent:



Code:
//JS LANGUAGE (function($) { // Function to check and update the language function updateLanguage() { var selectedOption = $("#jform_catid option:selected"); var data = selectedOption.attr('data-title'); var text = selectedOption.text(); // Check if data-title attribute exists or use the option text var language = data || text; if (language) { if (language.includes('English')) { // console.log('English'); $('#jform_language').val('en-GB'); $('#jform_language').trigger('change'); } else if (language.includes('中文')) { // console.log('中文'); $('#jform_language').val('zh-TW'); $('#jform_language').trigger('change'); } } } $(document).ready(function() { // Initial check on document ready updateLanguage(); // Check on category change $('select#jform_catid').on('change', function() { updateLanguage(); }); }); })(jQuery);


Category Structure:

- English
- 中文 (Chinese)

Last edit: 2 years 1 month ago by iamrobert.

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #84814 by micker
thanks

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline
Save