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I,eAAe,KAAK,cAAc,EAAE;YACtC,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;SAC7C;aAAM,IAAI,eAAe,KAAK,gBAAgB,EAAE;YAC/C,cAAc,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;SAC/C;QAED,SAAS,GAAG,QAAQ,CAAC;IACvB,CAAC;IAlBD,kCAkBC","sourcesContent":["import { getDocument } from './dom/getDocument';\nimport * as localStorage from './localStorage';\nimport * as sessionStorage from './sessionStorage';\n\n// Default to undefined so that we initialize on first read.\nlet _language: string | null;\n\nconst STORAGE_KEY = 'language';\n\n/**\n * Gets the language set for the page.\n * @param persistenceType - Where to persist the value. Default is `localStorage` if available.\n * (In version 8, the default will be `sessionStorage`.)\n */\nexport function getLanguage(\n persistenceType: 'localStorage' | 'sessionStorage' | 'none' = 'localStorage',\n): string | null {\n if (_language === undefined) {\n let doc = getDocument();\n const savedLanguage =\n persistenceType === 'localStorage'\n ? localStorage.getItem(STORAGE_KEY)\n : persistenceType === 'sessionStorage'\n ? sessionStorage.getItem(STORAGE_KEY)\n : undefined;\n\n if (savedLanguage) {\n _language = savedLanguage;\n }\n\n if (_language === undefined && doc) {\n _language = doc.documentElement.getAttribute('lang');\n }\n\n if (_language === undefined) {\n _language = 'en';\n }\n }\n\n return _language;\n}\n\n/**\n * Sets the language for the page (by adjusting the lang attribute of the html element).\n * @param language - Language to set.\n * @param persistenceType - Where to persist the value. Default is `localStorage` if available.\n * (In version 8, the default will be `sessionStorage`.)\n */\nexport function setLanguage(language: string, persistenceType?: 'localStorage' | 'sessionStorage' | 'none'): void;\n/**\n * Sets the language for the page (by adjusting the lang attribute of the html element).\n * @deprecated Use string parameter version.\n * @param language - Language to set.\n * @param avoidPersisting - If true, don't store the value.\n */\nexport function setLanguage(language: string, avoidPersisting?: boolean): void;\nexport function setLanguage(\n language: string,\n persistenceParam?: 'localStorage' | 'sessionStorage' | 'none' | boolean,\n): void {\n let doc = getDocument();\n\n if (doc) {\n doc.documentElement.setAttribute('lang', language);\n }\n\n const persistenceType = persistenceParam === true ? 'none' : !persistenceParam ? 'localStorage' : persistenceParam;\n if (persistenceType === 'localStorage') {\n localStorage.setItem(STORAGE_KEY, language);\n } else if (persistenceType === 'sessionStorage') {\n sessionStorage.setItem(STORAGE_KEY, language);\n }\n\n _language = language;\n}\n"]}
\No newline at end of file