locon 0.0.3 → 0.0.4
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/index.d.mts +26 -8
- package/dist/index.d.ts +26 -8
- package/dist/index.js +47 -16
- package/dist/index.mjs +47 -17
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -5,14 +5,32 @@ declare function L({ children }: Props): string;
|
|
|
5
5
|
|
|
6
6
|
declare function l(assetKey: string): string;
|
|
7
7
|
|
|
8
|
+
type Assets = Record<string, Record<string, string>>;
|
|
9
|
+
|
|
10
|
+
interface Settings {
|
|
11
|
+
assets: Assets;
|
|
12
|
+
currentLocale: string;
|
|
13
|
+
defaultLocale: string;
|
|
14
|
+
autodetect: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare global {
|
|
18
|
+
interface Window {
|
|
19
|
+
__LOCON_SETTINGS__: Settings;
|
|
20
|
+
}
|
|
21
|
+
var __LOCON_SETTINGS__: Settings;
|
|
22
|
+
namespace NodeJS {
|
|
23
|
+
interface Global {
|
|
24
|
+
__LOCON_SETTINGS__: Settings;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
declare function init(options?: {}): Settings;
|
|
29
|
+
declare function setLocale(locale: string): void;
|
|
30
|
+
|
|
8
31
|
declare const _default: {
|
|
9
|
-
init:
|
|
10
|
-
|
|
11
|
-
locales: {
|
|
12
|
-
en: {};
|
|
13
|
-
};
|
|
14
|
-
autodetect: boolean;
|
|
15
|
-
};
|
|
32
|
+
init: typeof init;
|
|
33
|
+
setLocale: typeof setLocale;
|
|
16
34
|
};
|
|
17
35
|
|
|
18
|
-
export { L, _default as default, l };
|
|
36
|
+
export { L, _default as default, l, setLocale };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,14 +5,32 @@ declare function L({ children }: Props): string;
|
|
|
5
5
|
|
|
6
6
|
declare function l(assetKey: string): string;
|
|
7
7
|
|
|
8
|
+
type Assets = Record<string, Record<string, string>>;
|
|
9
|
+
|
|
10
|
+
interface Settings {
|
|
11
|
+
assets: Assets;
|
|
12
|
+
currentLocale: string;
|
|
13
|
+
defaultLocale: string;
|
|
14
|
+
autodetect: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare global {
|
|
18
|
+
interface Window {
|
|
19
|
+
__LOCON_SETTINGS__: Settings;
|
|
20
|
+
}
|
|
21
|
+
var __LOCON_SETTINGS__: Settings;
|
|
22
|
+
namespace NodeJS {
|
|
23
|
+
interface Global {
|
|
24
|
+
__LOCON_SETTINGS__: Settings;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
declare function init(options?: {}): Settings;
|
|
29
|
+
declare function setLocale(locale: string): void;
|
|
30
|
+
|
|
8
31
|
declare const _default: {
|
|
9
|
-
init:
|
|
10
|
-
|
|
11
|
-
locales: {
|
|
12
|
-
en: {};
|
|
13
|
-
};
|
|
14
|
-
autodetect: boolean;
|
|
15
|
-
};
|
|
32
|
+
init: typeof init;
|
|
33
|
+
setLocale: typeof setLocale;
|
|
16
34
|
};
|
|
17
35
|
|
|
18
|
-
export { L, _default as default, l };
|
|
36
|
+
export { L, _default as default, l, setLocale };
|
package/dist/index.js
CHANGED
|
@@ -2,29 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
// src/functions/l.ts
|
|
6
|
-
function l(assetKey) {
|
|
7
|
-
return assetKey;
|
|
8
|
-
}
|
|
9
|
-
var l_default = l;
|
|
10
|
-
|
|
11
|
-
// src/components/L.ts
|
|
12
|
-
function L({ children }) {
|
|
13
|
-
return l_default(children);
|
|
14
|
-
}
|
|
15
|
-
var L_default = L;
|
|
16
|
-
|
|
17
5
|
// src/helpers/environment.ts
|
|
18
6
|
var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
19
7
|
|
|
20
8
|
// src/settings/index.ts
|
|
21
9
|
var defaultSettings = {
|
|
10
|
+
assets: { en: {} },
|
|
11
|
+
currentLocale: "en",
|
|
22
12
|
defaultLocale: "en",
|
|
23
|
-
locales: { en: {} },
|
|
24
13
|
autodetect: true
|
|
25
14
|
};
|
|
26
15
|
var globalSettings = defaultSettings;
|
|
27
|
-
|
|
16
|
+
function init(options = {}) {
|
|
28
17
|
globalSettings = { ...defaultSettings, ...options };
|
|
29
18
|
if (isBrowser) {
|
|
30
19
|
window.__LOCON_SETTINGS__ = globalSettings;
|
|
@@ -32,11 +21,53 @@ var init = (options = {}) => {
|
|
|
32
21
|
global.__LOCON_SETTINGS__ = globalSettings;
|
|
33
22
|
}
|
|
34
23
|
return globalSettings;
|
|
35
|
-
}
|
|
24
|
+
}
|
|
25
|
+
function getSettings() {
|
|
26
|
+
if (isBrowser) {
|
|
27
|
+
return window.__LOCON_SETTINGS__ || globalSettings;
|
|
28
|
+
} else {
|
|
29
|
+
return global.__LOCON_SETTINGS__ || globalSettings;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function getAssets() {
|
|
33
|
+
const settings = getSettings();
|
|
34
|
+
const { currentLocale, defaultLocale } = settings;
|
|
35
|
+
const assets = settings.assets[currentLocale] ?? settings.assets[defaultLocale];
|
|
36
|
+
return assets ?? {};
|
|
37
|
+
}
|
|
38
|
+
function getAsset(assetKey) {
|
|
39
|
+
const assets = getAssets();
|
|
40
|
+
return assets[assetKey] ?? "";
|
|
41
|
+
}
|
|
42
|
+
function setLocale(locale) {
|
|
43
|
+
if (!locale) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const settings = getSettings();
|
|
47
|
+
settings.currentLocale = locale;
|
|
48
|
+
init(settings);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/functions/l.ts
|
|
52
|
+
function l(assetKey) {
|
|
53
|
+
if (!assetKey) {
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
const asset = getAsset(assetKey);
|
|
57
|
+
return asset;
|
|
58
|
+
}
|
|
59
|
+
var l_default = l;
|
|
60
|
+
|
|
61
|
+
// src/components/L.ts
|
|
62
|
+
function L({ children }) {
|
|
63
|
+
return l_default(children);
|
|
64
|
+
}
|
|
65
|
+
var L_default = L;
|
|
36
66
|
|
|
37
67
|
// src/index.ts
|
|
38
|
-
var src_default = { init };
|
|
68
|
+
var src_default = { init, setLocale };
|
|
39
69
|
|
|
40
70
|
exports.L = L_default;
|
|
41
71
|
exports.default = src_default;
|
|
42
72
|
exports.l = l_default;
|
|
73
|
+
exports.setLocale = setLocale;
|
package/dist/index.mjs
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
// src/functions/l.ts
|
|
2
|
-
function l(assetKey) {
|
|
3
|
-
return assetKey;
|
|
4
|
-
}
|
|
5
|
-
var l_default = l;
|
|
6
|
-
|
|
7
|
-
// src/components/L.ts
|
|
8
|
-
function L({ children }) {
|
|
9
|
-
return l_default(children);
|
|
10
|
-
}
|
|
11
|
-
var L_default = L;
|
|
12
|
-
|
|
13
1
|
// src/helpers/environment.ts
|
|
14
2
|
var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
15
3
|
|
|
16
4
|
// src/settings/index.ts
|
|
17
5
|
var defaultSettings = {
|
|
6
|
+
assets: { en: {} },
|
|
7
|
+
currentLocale: "en",
|
|
18
8
|
defaultLocale: "en",
|
|
19
|
-
locales: { en: {} },
|
|
20
9
|
autodetect: true
|
|
21
10
|
};
|
|
22
11
|
var globalSettings = defaultSettings;
|
|
23
|
-
|
|
12
|
+
function init(options = {}) {
|
|
24
13
|
globalSettings = { ...defaultSettings, ...options };
|
|
25
14
|
if (isBrowser) {
|
|
26
15
|
window.__LOCON_SETTINGS__ = globalSettings;
|
|
@@ -28,9 +17,50 @@ var init = (options = {}) => {
|
|
|
28
17
|
global.__LOCON_SETTINGS__ = globalSettings;
|
|
29
18
|
}
|
|
30
19
|
return globalSettings;
|
|
31
|
-
}
|
|
20
|
+
}
|
|
21
|
+
function getSettings() {
|
|
22
|
+
if (isBrowser) {
|
|
23
|
+
return window.__LOCON_SETTINGS__ || globalSettings;
|
|
24
|
+
} else {
|
|
25
|
+
return global.__LOCON_SETTINGS__ || globalSettings;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function getAssets() {
|
|
29
|
+
const settings = getSettings();
|
|
30
|
+
const { currentLocale, defaultLocale } = settings;
|
|
31
|
+
const assets = settings.assets[currentLocale] ?? settings.assets[defaultLocale];
|
|
32
|
+
return assets ?? {};
|
|
33
|
+
}
|
|
34
|
+
function getAsset(assetKey) {
|
|
35
|
+
const assets = getAssets();
|
|
36
|
+
return assets[assetKey] ?? "";
|
|
37
|
+
}
|
|
38
|
+
function setLocale(locale) {
|
|
39
|
+
if (!locale) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const settings = getSettings();
|
|
43
|
+
settings.currentLocale = locale;
|
|
44
|
+
init(settings);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/functions/l.ts
|
|
48
|
+
function l(assetKey) {
|
|
49
|
+
if (!assetKey) {
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
const asset = getAsset(assetKey);
|
|
53
|
+
return asset;
|
|
54
|
+
}
|
|
55
|
+
var l_default = l;
|
|
56
|
+
|
|
57
|
+
// src/components/L.ts
|
|
58
|
+
function L({ children }) {
|
|
59
|
+
return l_default(children);
|
|
60
|
+
}
|
|
61
|
+
var L_default = L;
|
|
32
62
|
|
|
33
63
|
// src/index.ts
|
|
34
|
-
var src_default = { init };
|
|
64
|
+
var src_default = { init, setLocale };
|
|
35
65
|
|
|
36
|
-
export { L_default as L, src_default as default, l_default as l };
|
|
66
|
+
export { L_default as L, src_default as default, l_default as l, setLocale };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locon",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "locon is a simple and lightweight library for React and React Native that provides a simple way to manage translations in your app.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|