63 lines
3.0 KiB
Plaintext
63 lines
3.0 KiB
Plaintext
import {isRTL as $148a7a147e38ea7f$export$702d680b21cbd764} from "./utils.module.js";
|
|
import {useState as $ffhGL$useState, useEffect as $ffhGL$useEffect} from "react";
|
|
import {useIsSSR as $ffhGL$useIsSSR} from "@react-aria/ssr";
|
|
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/
|
|
|
|
|
|
// Locale passed from server by PackageLocalizationProvider.
|
|
const $1e5a04cdaf7d1af8$var$localeSymbol = Symbol.for('react-aria.i18n.locale');
|
|
function $1e5a04cdaf7d1af8$export$f09106e7c6677ec5() {
|
|
let locale = typeof window !== 'undefined' && window[$1e5a04cdaf7d1af8$var$localeSymbol] || typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage) || 'en-US';
|
|
try {
|
|
Intl.DateTimeFormat.supportedLocalesOf([
|
|
locale
|
|
]);
|
|
} catch {
|
|
locale = 'en-US';
|
|
}
|
|
return {
|
|
locale: locale,
|
|
direction: (0, $148a7a147e38ea7f$export$702d680b21cbd764)(locale) ? 'rtl' : 'ltr'
|
|
};
|
|
}
|
|
let $1e5a04cdaf7d1af8$var$currentLocale = $1e5a04cdaf7d1af8$export$f09106e7c6677ec5();
|
|
let $1e5a04cdaf7d1af8$var$listeners = new Set();
|
|
function $1e5a04cdaf7d1af8$var$updateLocale() {
|
|
$1e5a04cdaf7d1af8$var$currentLocale = $1e5a04cdaf7d1af8$export$f09106e7c6677ec5();
|
|
for (let listener of $1e5a04cdaf7d1af8$var$listeners)listener($1e5a04cdaf7d1af8$var$currentLocale);
|
|
}
|
|
function $1e5a04cdaf7d1af8$export$188ec29ebc2bdc3a() {
|
|
let isSSR = (0, $ffhGL$useIsSSR)();
|
|
let [defaultLocale, setDefaultLocale] = (0, $ffhGL$useState)($1e5a04cdaf7d1af8$var$currentLocale);
|
|
(0, $ffhGL$useEffect)(()=>{
|
|
if ($1e5a04cdaf7d1af8$var$listeners.size === 0) window.addEventListener('languagechange', $1e5a04cdaf7d1af8$var$updateLocale);
|
|
$1e5a04cdaf7d1af8$var$listeners.add(setDefaultLocale);
|
|
return ()=>{
|
|
$1e5a04cdaf7d1af8$var$listeners.delete(setDefaultLocale);
|
|
if ($1e5a04cdaf7d1af8$var$listeners.size === 0) window.removeEventListener('languagechange', $1e5a04cdaf7d1af8$var$updateLocale);
|
|
};
|
|
}, []);
|
|
// We cannot determine the browser's language on the server, so default to
|
|
// en-US. This will be updated after hydration on the client to the correct value.
|
|
if (isSSR) return {
|
|
locale: 'en-US',
|
|
direction: 'ltr'
|
|
};
|
|
return defaultLocale;
|
|
}
|
|
|
|
|
|
export {$1e5a04cdaf7d1af8$export$f09106e7c6677ec5 as getDefaultLocale, $1e5a04cdaf7d1af8$export$188ec29ebc2bdc3a as useDefaultLocale};
|
|
//# sourceMappingURL=useDefaultLocale.module.js.map
|