diff --git a/root/etc/e-smith/templates/usr/share/smanager/themes/default/public/js/flag-by-locale.js b/root/etc/e-smith/templates/usr/share/smanager/themes/default/public/js/flag-by-locale.js new file mode 100644 index 0000000..3c7ba26 --- /dev/null +++ b/root/etc/e-smith/templates/usr/share/smanager/themes/default/public/js/flag-by-locale.js @@ -0,0 +1,27 @@ +document.addEventListener('DOMContentLoaded', () => { + const flagContainer = document.getElementById('flag-container'); + + // Function to get the browser's locale + function getBrowserLocale() { + return navigator.language || navigator.userLanguage; + } + + // Function to map locale to country code + function getCountryCodeFromLocale(locale) { + const localeParts = locale.split('-'); + return localeParts.length > 1 ? localeParts[1] : localeParts[0]; + } + + // Function to create and display the flag icon + function displayFlagIcon(countryCode) { + const flagIcon = document.createElement('span'); + flagIcon.className = `flag-icon flag-icon-${countryCode.toLowerCase()}`; + flagIcon.id = 'flag-icon'; + flagContainer.appendChild(flagIcon); + } + + // Main logic + const locale = getBrowserLocale(); + const countryCode = getCountryCodeFromLocale(locale); + displayFlagIcon(countryCode); +});