From ba431a8a7dd1b5d3aacecb99e2aed3b4427c71bf Mon Sep 17 00:00:00 2001 From: Brian Read Date: Sat, 27 Jul 2024 22:07:10 +0100 Subject: [PATCH] Add in js code for flag icon --- .../default/public/js/flag-by-locale.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 root/etc/e-smith/templates/usr/share/smanager/themes/default/public/js/flag-by-locale.js 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); +});