@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.55 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{makeHandle as e}from"../core/handleUtils.js";import"../core/has.js";let n,t;const o=globalThis.esriConfig?.locale??globalThis.dojoConfig?.locale,r=globalThis.document?.documentElement;function a(){const e=r?.getAttribute("lang"),n=globalThis.navigator?.language;return o??e??n??"en"}function i(){return void 0===t&&(t=a()),t}function l(e){n=e||void 0,m()}const c=/^(?<language>[a-z]{2,3})(?:-[a-z]{3})?(?:-[A-Z][a-z]{3})?(?:-(?<region>[A-Z]{2}|\d{3}))?(?:-.*)?$/;function s(e=i()){return c.exec(e)?.groups}function u(e=i()){const n=s(e)?.language;return"he"===n||"ar"===n}const g=[],f=new Map;function h(){const e=Array.from(f.values())[0];f.clear();const n=g.length;if(0!==n)throw new Error(`Unexpected ${n} locale change listeners still active.${e?` For example:\n${e}`:" Set enableListenerTracing in esri/intl/locale.ts to include a stack trace."}`)}function d(n){return g.push(n),e((()=>{g.splice(g.indexOf(n),1)}))}const p=[];function b(n){return p.push(n),e((()=>p.splice(p.indexOf(n),1)))}function m(){const e=n??a();t!==e&&([...p].forEach((n=>n(e))),t=e,[...g].forEach((n=>n(e))))}if(globalThis.addEventListener?.("languagechange",m),r){new MutationObserver((()=>{m()})).observe(r,{attributeFilter:["lang"]})}export{h as assertNoLocaleChangeListeners,b as beforeLocaleChange,a as getDefaultLocale,i as getLocale,s as getLocaleParts,d as onLocaleChange,u as prefersRTL,l as setLocale};