locon 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/LText.d.mts +10 -0
- package/dist/components/LText.d.ts +10 -0
- package/dist/components/LText.js +41 -0
- package/dist/components/LText.mjs +11 -0
- package/dist/hooks/useLocon.d.mts +6 -0
- package/dist/hooks/useLocon.d.ts +6 -0
- package/dist/hooks/useLocon.js +30 -0
- package/dist/hooks/useLocon.mjs +10 -0
- package/dist/index.d.mts +7 -22
- package/dist/index.d.ts +7 -22
- package/dist/types/Assets.d.mts +3 -0
- package/dist/types/Assets.d.ts +3 -0
- package/dist/types/Assets.js +16 -0
- package/dist/types/Assets.mjs +0 -0
- package/dist/types/LoconContext.d.mts +12 -0
- package/dist/types/LoconContext.d.ts +12 -0
- package/dist/types/LoconContext.js +16 -0
- package/dist/types/LoconContext.mjs +0 -0
- package/dist/utils/getSystemLanguage.d.mts +7 -0
- package/dist/utils/getSystemLanguage.d.ts +7 -0
- package/dist/utils/getSystemLanguage.js +125 -0
- package/dist/utils/getSystemLanguage.mjs +105 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactElement, ComponentProps } from 'react';
|
|
2
|
+
import { Text } from 'react-native';
|
|
3
|
+
|
|
4
|
+
interface Props extends ComponentProps<typeof Text> {
|
|
5
|
+
children: string;
|
|
6
|
+
assetKey?: string;
|
|
7
|
+
}
|
|
8
|
+
declare function LText({ children, assetKey, ...props }: Props): ReactElement;
|
|
9
|
+
|
|
10
|
+
export { LText as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactElement, ComponentProps } from 'react';
|
|
2
|
+
import { Text } from 'react-native';
|
|
3
|
+
|
|
4
|
+
interface Props extends ComponentProps<typeof Text> {
|
|
5
|
+
children: string;
|
|
6
|
+
assetKey?: string;
|
|
7
|
+
}
|
|
8
|
+
declare function LText({ children, assetKey, ...props }: Props): ReactElement;
|
|
9
|
+
|
|
10
|
+
export { LText as default };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var LText_exports = {};
|
|
30
|
+
__export(LText_exports, {
|
|
31
|
+
default: () => LText_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(LText_exports);
|
|
34
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
+
var import_react_native = require("react-native");
|
|
36
|
+
var import_useLocon = __toESM(require("../hooks/useLocon"));
|
|
37
|
+
function LText({ children, assetKey, ...props }) {
|
|
38
|
+
const { l } = (0, import_useLocon.default)();
|
|
39
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { ...props, children: l(assetKey || children) });
|
|
40
|
+
}
|
|
41
|
+
var LText_default = LText;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Text } from "react-native";
|
|
3
|
+
import useLocon from "../hooks/useLocon";
|
|
4
|
+
function LText({ children, assetKey, ...props }) {
|
|
5
|
+
const { l } = useLocon();
|
|
6
|
+
return /* @__PURE__ */ jsx(Text, { ...props, children: l(assetKey || children) });
|
|
7
|
+
}
|
|
8
|
+
var LText_default = LText;
|
|
9
|
+
export {
|
|
10
|
+
LText_default as default
|
|
11
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useLocon_exports = {};
|
|
20
|
+
__export(useLocon_exports, {
|
|
21
|
+
default: () => useLocon_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useLocon_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
var import__ = require("../index");
|
|
26
|
+
function useLocon() {
|
|
27
|
+
const locon = (0, import_react.useContext)(import__.LoconContext);
|
|
28
|
+
return locon;
|
|
29
|
+
}
|
|
30
|
+
var useLocon_default = useLocon;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactElement,
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
l: (assetKey: string) => string;
|
|
9
|
-
assets: Assets;
|
|
10
|
-
currentLocale: string;
|
|
11
|
-
defaultLocale: string;
|
|
12
|
-
autodetect: boolean;
|
|
13
|
-
setLocale: (locale: string) => void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface Props$1 extends ComponentProps<typeof Text> {
|
|
17
|
-
children: string;
|
|
18
|
-
assetKey?: string;
|
|
19
|
-
}
|
|
20
|
-
declare function LText({ children, assetKey, ...props }: Props$1): ReactElement;
|
|
21
|
-
|
|
22
|
-
declare function useLocon(): LoconContext$1;
|
|
2
|
+
import { ReactElement, PropsWithChildren } from 'react';
|
|
3
|
+
import LoconContext$1 from './types/LoconContext.mjs';
|
|
4
|
+
export { default as LText } from './components/LText.mjs';
|
|
5
|
+
export { default as useLocon } from './hooks/useLocon.mjs';
|
|
6
|
+
import './types/Assets.mjs';
|
|
7
|
+
import 'react-native';
|
|
23
8
|
|
|
24
9
|
declare const LoconContext: react.Context<LoconContext$1>;
|
|
25
10
|
interface Props extends PropsWithChildren {
|
|
@@ -31,4 +16,4 @@ interface Props extends PropsWithChildren {
|
|
|
31
16
|
}
|
|
32
17
|
declare function Locon({ children, assets, currentLocale: currentLocaleProps, defaultLocale, projectLocale, autodetect, }: Props): ReactElement;
|
|
33
18
|
|
|
34
|
-
export {
|
|
19
|
+
export { LoconContext, Locon as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactElement,
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
l: (assetKey: string) => string;
|
|
9
|
-
assets: Assets;
|
|
10
|
-
currentLocale: string;
|
|
11
|
-
defaultLocale: string;
|
|
12
|
-
autodetect: boolean;
|
|
13
|
-
setLocale: (locale: string) => void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface Props$1 extends ComponentProps<typeof Text> {
|
|
17
|
-
children: string;
|
|
18
|
-
assetKey?: string;
|
|
19
|
-
}
|
|
20
|
-
declare function LText({ children, assetKey, ...props }: Props$1): ReactElement;
|
|
21
|
-
|
|
22
|
-
declare function useLocon(): LoconContext$1;
|
|
2
|
+
import { ReactElement, PropsWithChildren } from 'react';
|
|
3
|
+
import LoconContext$1 from './types/LoconContext.js';
|
|
4
|
+
export { default as LText } from './components/LText.js';
|
|
5
|
+
export { default as useLocon } from './hooks/useLocon.js';
|
|
6
|
+
import './types/Assets.js';
|
|
7
|
+
import 'react-native';
|
|
23
8
|
|
|
24
9
|
declare const LoconContext: react.Context<LoconContext$1>;
|
|
25
10
|
interface Props extends PropsWithChildren {
|
|
@@ -31,4 +16,4 @@ interface Props extends PropsWithChildren {
|
|
|
31
16
|
}
|
|
32
17
|
declare function Locon({ children, assets, currentLocale: currentLocaleProps, defaultLocale, projectLocale, autodetect, }: Props): ReactElement;
|
|
33
18
|
|
|
34
|
-
export {
|
|
19
|
+
export { LoconContext, Locon as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var Assets_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(Assets_exports);
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Assets from './Assets.mjs';
|
|
2
|
+
|
|
3
|
+
interface LoconContext {
|
|
4
|
+
l: (assetKey: string) => string;
|
|
5
|
+
assets: Assets;
|
|
6
|
+
currentLocale: string;
|
|
7
|
+
defaultLocale: string;
|
|
8
|
+
autodetect: boolean;
|
|
9
|
+
setLocale: (locale: string) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type { LoconContext as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Assets from './Assets.js';
|
|
2
|
+
|
|
3
|
+
interface LoconContext {
|
|
4
|
+
l: (assetKey: string) => string;
|
|
5
|
+
assets: Assets;
|
|
6
|
+
currentLocale: string;
|
|
7
|
+
defaultLocale: string;
|
|
8
|
+
autodetect: boolean;
|
|
9
|
+
setLocale: (locale: string) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type { LoconContext as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var LoconContext_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(LoconContext_exports);
|
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects the system language and returns the best matching available locale.
|
|
3
|
+
* Uses react-native-localize if available, otherwise falls back to native APIs.
|
|
4
|
+
*/
|
|
5
|
+
declare function getSystemLanguage(availableLocales?: string[]): string | null;
|
|
6
|
+
|
|
7
|
+
export { getSystemLanguage as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects the system language and returns the best matching available locale.
|
|
3
|
+
* Uses react-native-localize if available, otherwise falls back to native APIs.
|
|
4
|
+
*/
|
|
5
|
+
declare function getSystemLanguage(availableLocales?: string[]): string | null;
|
|
6
|
+
|
|
7
|
+
export { getSystemLanguage as default };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var getSystemLanguage_exports = {};
|
|
20
|
+
__export(getSystemLanguage_exports, {
|
|
21
|
+
default: () => getSystemLanguage_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(getSystemLanguage_exports);
|
|
24
|
+
function getSystemLanguage(availableLocales) {
|
|
25
|
+
if (!availableLocales?.length) return null;
|
|
26
|
+
try {
|
|
27
|
+
try {
|
|
28
|
+
const RNLocalize = require("react-native-localize");
|
|
29
|
+
if (typeof RNLocalize.findBestLanguageTag === "function") {
|
|
30
|
+
const best = RNLocalize.findBestLanguageTag(availableLocales);
|
|
31
|
+
if (best?.languageTag) {
|
|
32
|
+
const { languageTag } = best;
|
|
33
|
+
const languageCode = languageTag.split("-")[0]?.toLowerCase();
|
|
34
|
+
if (availableLocales.includes(languageTag)) {
|
|
35
|
+
return languageTag;
|
|
36
|
+
}
|
|
37
|
+
if (languageCode && availableLocales.includes(languageCode)) {
|
|
38
|
+
return languageCode;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (typeof RNLocalize.getLocales === "function") {
|
|
43
|
+
const locales = RNLocalize.getLocales();
|
|
44
|
+
const matchedLocale = locales.find((locale) => {
|
|
45
|
+
const languageCode = locale.languageCode.toLowerCase();
|
|
46
|
+
if (languageCode && availableLocales.includes(languageCode)) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (locale.languageTag) {
|
|
50
|
+
const tagCode = locale.languageTag.split("-")[0]?.toLowerCase();
|
|
51
|
+
if (tagCode && availableLocales.includes(tagCode)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
});
|
|
57
|
+
if (matchedLocale) {
|
|
58
|
+
const languageCode = matchedLocale.languageCode.toLowerCase();
|
|
59
|
+
if (availableLocales.includes(languageCode)) {
|
|
60
|
+
return languageCode;
|
|
61
|
+
}
|
|
62
|
+
if (matchedLocale.languageTag) {
|
|
63
|
+
const tagCode = matchedLocale.languageTag.split("-")[0]?.toLowerCase();
|
|
64
|
+
if (tagCode && availableLocales.includes(tagCode)) {
|
|
65
|
+
return tagCode;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
} catch (localizeError) {
|
|
71
|
+
console.warn("[locon] \u274C react-native-localize error:", localizeError);
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const { NativeModules, Platform } = require("react-native");
|
|
75
|
+
if (Platform.OS === "ios") {
|
|
76
|
+
const { SettingsManager } = NativeModules;
|
|
77
|
+
if (SettingsManager?.settings?.AppleLanguages) {
|
|
78
|
+
const appleLanguages = SettingsManager.settings.AppleLanguages;
|
|
79
|
+
const supportedLanguage = appleLanguages.map((lang) => lang.split("-")[0]?.toLowerCase()).filter((languageCode) => Boolean(languageCode)).find((languageCode) => availableLocales.includes(languageCode));
|
|
80
|
+
if (supportedLanguage) {
|
|
81
|
+
return supportedLanguage;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const { I18nManager } = NativeModules;
|
|
85
|
+
if (I18nManager?.localeIdentifier) {
|
|
86
|
+
const languageCode = I18nManager.localeIdentifier.split("-")[0]?.toLowerCase();
|
|
87
|
+
if (languageCode) {
|
|
88
|
+
const supportedLanguage = availableLocales.find((locale) => locale === languageCode);
|
|
89
|
+
if (supportedLanguage) {
|
|
90
|
+
return supportedLanguage;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
} else if (Platform.OS === "android") {
|
|
95
|
+
const { I18nManager } = NativeModules;
|
|
96
|
+
if (I18nManager?.localeIdentifier) {
|
|
97
|
+
const languageCode = I18nManager.localeIdentifier.split("-")[0]?.toLowerCase();
|
|
98
|
+
if (languageCode) {
|
|
99
|
+
const supportedLanguage = availableLocales.find((locale) => locale === languageCode);
|
|
100
|
+
if (supportedLanguage) {
|
|
101
|
+
return supportedLanguage;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (rnError) {
|
|
107
|
+
console.warn("[locon] \u274C react-native error:", rnError);
|
|
108
|
+
}
|
|
109
|
+
const systemLocale = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
110
|
+
if (systemLocale) {
|
|
111
|
+
const languageCode = systemLocale.split("-")[0]?.toLowerCase();
|
|
112
|
+
if (languageCode) {
|
|
113
|
+
const supportedLanguage = availableLocales.find((locale) => locale === languageCode);
|
|
114
|
+
if (supportedLanguage) {
|
|
115
|
+
return supportedLanguage;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.warn("[locon] \u274C Could not detect system language:", error);
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
var getSystemLanguage_default = getSystemLanguage;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
function getSystemLanguage(availableLocales) {
|
|
2
|
+
if (!availableLocales?.length) return null;
|
|
3
|
+
try {
|
|
4
|
+
try {
|
|
5
|
+
const RNLocalize = require("react-native-localize");
|
|
6
|
+
if (typeof RNLocalize.findBestLanguageTag === "function") {
|
|
7
|
+
const best = RNLocalize.findBestLanguageTag(availableLocales);
|
|
8
|
+
if (best?.languageTag) {
|
|
9
|
+
const { languageTag } = best;
|
|
10
|
+
const languageCode = languageTag.split("-")[0]?.toLowerCase();
|
|
11
|
+
if (availableLocales.includes(languageTag)) {
|
|
12
|
+
return languageTag;
|
|
13
|
+
}
|
|
14
|
+
if (languageCode && availableLocales.includes(languageCode)) {
|
|
15
|
+
return languageCode;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (typeof RNLocalize.getLocales === "function") {
|
|
20
|
+
const locales = RNLocalize.getLocales();
|
|
21
|
+
const matchedLocale = locales.find((locale) => {
|
|
22
|
+
const languageCode = locale.languageCode.toLowerCase();
|
|
23
|
+
if (languageCode && availableLocales.includes(languageCode)) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (locale.languageTag) {
|
|
27
|
+
const tagCode = locale.languageTag.split("-")[0]?.toLowerCase();
|
|
28
|
+
if (tagCode && availableLocales.includes(tagCode)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
});
|
|
34
|
+
if (matchedLocale) {
|
|
35
|
+
const languageCode = matchedLocale.languageCode.toLowerCase();
|
|
36
|
+
if (availableLocales.includes(languageCode)) {
|
|
37
|
+
return languageCode;
|
|
38
|
+
}
|
|
39
|
+
if (matchedLocale.languageTag) {
|
|
40
|
+
const tagCode = matchedLocale.languageTag.split("-")[0]?.toLowerCase();
|
|
41
|
+
if (tagCode && availableLocales.includes(tagCode)) {
|
|
42
|
+
return tagCode;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
} catch (localizeError) {
|
|
48
|
+
console.warn("[locon] \u274C react-native-localize error:", localizeError);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const { NativeModules, Platform } = require("react-native");
|
|
52
|
+
if (Platform.OS === "ios") {
|
|
53
|
+
const { SettingsManager } = NativeModules;
|
|
54
|
+
if (SettingsManager?.settings?.AppleLanguages) {
|
|
55
|
+
const appleLanguages = SettingsManager.settings.AppleLanguages;
|
|
56
|
+
const supportedLanguage = appleLanguages.map((lang) => lang.split("-")[0]?.toLowerCase()).filter((languageCode) => Boolean(languageCode)).find((languageCode) => availableLocales.includes(languageCode));
|
|
57
|
+
if (supportedLanguage) {
|
|
58
|
+
return supportedLanguage;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const { I18nManager } = NativeModules;
|
|
62
|
+
if (I18nManager?.localeIdentifier) {
|
|
63
|
+
const languageCode = I18nManager.localeIdentifier.split("-")[0]?.toLowerCase();
|
|
64
|
+
if (languageCode) {
|
|
65
|
+
const supportedLanguage = availableLocales.find((locale) => locale === languageCode);
|
|
66
|
+
if (supportedLanguage) {
|
|
67
|
+
return supportedLanguage;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} else if (Platform.OS === "android") {
|
|
72
|
+
const { I18nManager } = NativeModules;
|
|
73
|
+
if (I18nManager?.localeIdentifier) {
|
|
74
|
+
const languageCode = I18nManager.localeIdentifier.split("-")[0]?.toLowerCase();
|
|
75
|
+
if (languageCode) {
|
|
76
|
+
const supportedLanguage = availableLocales.find((locale) => locale === languageCode);
|
|
77
|
+
if (supportedLanguage) {
|
|
78
|
+
return supportedLanguage;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch (rnError) {
|
|
84
|
+
console.warn("[locon] \u274C react-native error:", rnError);
|
|
85
|
+
}
|
|
86
|
+
const systemLocale = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
87
|
+
if (systemLocale) {
|
|
88
|
+
const languageCode = systemLocale.split("-")[0]?.toLowerCase();
|
|
89
|
+
if (languageCode) {
|
|
90
|
+
const supportedLanguage = availableLocales.find((locale) => locale === languageCode);
|
|
91
|
+
if (supportedLanguage) {
|
|
92
|
+
return supportedLanguage;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.warn("[locon] \u274C Could not detect system language:", error);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
var getSystemLanguage_default = getSystemLanguage;
|
|
103
|
+
export {
|
|
104
|
+
getSystemLanguage_default as default
|
|
105
|
+
};
|
package/package.json
CHANGED