@almighty-shogun/utils 1.6.0 → 1.8.1
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.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/initApplication.d.ts +8 -0
- package/dist/initApplication.d.ts.map +1 -0
- package/dist/initApplication.js +9 -0
- package/dist/internal/getCurrentRouteName.js +3 -3
- package/dist/internal/getVueInstance.d.ts +8 -0
- package/dist/internal/getVueInstance.d.ts.map +1 -0
- package/dist/internal/getVueInstance.js +9 -0
- package/dist/internal/localization.d.ts +7 -7
- package/dist/internal/localization.d.ts.map +1 -1
- package/dist/internal/localization.js +18 -10
- package/dist/internal/types.d.ts +11 -0
- package/dist/internal/types.d.ts.map +1 -1
- package/dist/reload.d.ts +2 -0
- package/dist/reload.d.ts.map +1 -0
- package/dist/reload.js +3 -0
- package/dist/useDarkTheme.d.ts +2 -0
- package/dist/useDarkTheme.d.ts.map +1 -0
- package/dist/useDarkTheme.js +3 -0
- package/dist/vuei18n.d.ts +10 -0
- package/dist/vuei18n.d.ts.map +1 -0
- package/dist/vuei18n.js +21 -0
- package/package.json +2 -2
- package/src/index.ts +6 -1
- package/src/initApplication.ts +18 -0
- package/src/internal/getCurrentRouteName.ts +3 -3
- package/src/internal/getVueInstance.ts +17 -0
- package/src/internal/localization.ts +21 -13
- package/src/internal/types.ts +14 -0
- package/src/reload.ts +3 -0
- package/src/useDarkTheme.ts +3 -0
- package/src/vuei18n.ts +37 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { Weather, WeatherItem } from './internal/weather';
|
|
2
|
-
export {
|
|
2
|
+
export { getLanguage, getLanguages } from './internal/localization';
|
|
3
3
|
export { default as containsRoutePrefix } from './containsRoutePrefix';
|
|
4
4
|
export { default as disableZoom } from './disableZoom';
|
|
5
5
|
export { default as formatCelsius } from './formatCelsius';
|
|
@@ -18,7 +18,11 @@ export { default as formatTime } from './formatTime';
|
|
|
18
18
|
export { default as formatWeekday } from './formatWeekday';
|
|
19
19
|
export { default as getWeather } from './getWeather';
|
|
20
20
|
export { default as hasCurrentRoute } from './hasCurrentRoute';
|
|
21
|
+
export { default as initApplication } from './initApplication';
|
|
21
22
|
export { default as isBeforeNow } from './isBeforeNow';
|
|
22
23
|
export { default as isCurrentRoute } from './isCurrentRoute';
|
|
24
|
+
export { default as reload } from './reload';
|
|
23
25
|
export { default as scrollToTop } from './scrollToTop';
|
|
26
|
+
export { default as useDarkTheme } from './useDarkTheme';
|
|
27
|
+
export * from './vuei18n';
|
|
24
28
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC9D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAEnE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC1E,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAChE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAExD,cAAc,WAAW,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getLanguage, getLanguages } from './internal/localization';
|
|
2
2
|
export { default as containsRoutePrefix } from './containsRoutePrefix';
|
|
3
3
|
export { default as disableZoom } from './disableZoom';
|
|
4
4
|
export { default as formatCelsius } from './formatCelsius';
|
|
@@ -17,6 +17,10 @@ export { default as formatTime } from './formatTime';
|
|
|
17
17
|
export { default as formatWeekday } from './formatWeekday';
|
|
18
18
|
export { default as getWeather } from './getWeather';
|
|
19
19
|
export { default as hasCurrentRoute } from './hasCurrentRoute';
|
|
20
|
+
export { default as initApplication } from './initApplication';
|
|
20
21
|
export { default as isBeforeNow } from './isBeforeNow';
|
|
21
22
|
export { default as isCurrentRoute } from './isCurrentRoute';
|
|
23
|
+
export { default as reload } from './reload';
|
|
22
24
|
export { default as scrollToTop } from './scrollToTop';
|
|
25
|
+
export { default as useDarkTheme } from './useDarkTheme';
|
|
26
|
+
export * from './vuei18n';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initApplication.d.ts","sourceRoot":"","sources":["../src/initApplication.ts"],"names":[],"mappings":"AAGA,KAAK,iBAAiB,GAAG;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAA;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAQxD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import disableZoom from './disableZoom';
|
|
2
|
+
import useDarkTheme from './useDarkTheme';
|
|
3
|
+
export default function (config) {
|
|
4
|
+
document.documentElement.setAttribute("lang", config.locale ?? "en");
|
|
5
|
+
useDarkTheme(config.isDarkTheme ?? false);
|
|
6
|
+
if (config.isZoomDisabled) {
|
|
7
|
+
disableZoom();
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import getVueInstance from './getVueInstance';
|
|
2
2
|
export default function () {
|
|
3
|
-
const
|
|
4
|
-
return
|
|
3
|
+
const { route } = getVueInstance();
|
|
4
|
+
return route?.name?.toString() ?? "";
|
|
5
5
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getVueInstance.d.ts","sourceRoot":"","sources":["../../src/internal/getVueInstance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE1C,KAAK,WAAW,GAAG;IACf,IAAI,EAAE,IAAI,GAAC,IAAI,CAAC;IAChB,KAAK,EAAE,KAAK,GAAC,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,CAAC,OAAO,cAAc,WAAW,CAQtC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getCurrentInstance } from 'vue';
|
|
2
|
+
export default function () {
|
|
3
|
+
const instance = getCurrentInstance();
|
|
4
|
+
const globalProperties = instance?.appContext.config.globalProperties;
|
|
5
|
+
return {
|
|
6
|
+
i18n: globalProperties?.$i18n ?? null,
|
|
7
|
+
route: globalProperties?.$route ?? null,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type Language = {
|
|
2
2
|
name: string;
|
|
3
3
|
code: string;
|
|
4
4
|
flag: {
|
|
@@ -6,11 +6,11 @@ export type Country = {
|
|
|
6
6
|
rounded: string;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
export type
|
|
10
|
-
export type LocalizationCountries = Record<
|
|
11
|
-
declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function
|
|
9
|
+
export type LanguageCode = keyof typeof languagesMap;
|
|
10
|
+
export type LocalizationCountries = Record<LanguageCode, Language>;
|
|
11
|
+
declare const languagesMap: Record<string, Language>;
|
|
12
|
+
export declare const languages: LocalizationCountries;
|
|
13
|
+
export declare function getLanguage(code: LanguageCode): Language | null;
|
|
14
|
+
export declare function getLanguages(): Language[];
|
|
15
15
|
export {};
|
|
16
16
|
//# sourceMappingURL=localization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../src/internal/localization.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../src/internal/localization.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;KAAE,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,OAAO,YAAY,CAAC;AACrD,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;AAEnE,QAAA,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAyC1C,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,qBAA6D,CAAC;AAEtF,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,QAAQ,GAAC,IAAI,CAE7D;AAED,wBAAgB,YAAY,IAAI,QAAQ,EAAE,CAEzC"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
const
|
|
1
|
+
const languagesMap = {
|
|
2
|
+
en: {
|
|
3
|
+
name: "English",
|
|
4
|
+
code: "en",
|
|
5
|
+
flag: {
|
|
6
|
+
plain: "images/country-flags/flag-united-kingdom",
|
|
7
|
+
rounded: "images/country-flags/rounded/flag-united-kingdom",
|
|
8
|
+
}
|
|
9
|
+
},
|
|
2
10
|
nl: {
|
|
3
|
-
name: "
|
|
11
|
+
name: "Dutch",
|
|
4
12
|
code: "nl",
|
|
5
13
|
flag: {
|
|
6
14
|
plain: "images/country-flags/flag-netherlands",
|
|
@@ -8,7 +16,7 @@ const countriesMap = {
|
|
|
8
16
|
}
|
|
9
17
|
},
|
|
10
18
|
fr: {
|
|
11
|
-
name: "
|
|
19
|
+
name: "French",
|
|
12
20
|
code: "fr",
|
|
13
21
|
flag: {
|
|
14
22
|
plain: "images/country-flags/flag-france",
|
|
@@ -16,7 +24,7 @@ const countriesMap = {
|
|
|
16
24
|
}
|
|
17
25
|
},
|
|
18
26
|
de: {
|
|
19
|
-
name: "
|
|
27
|
+
name: "German",
|
|
20
28
|
code: "de",
|
|
21
29
|
flag: {
|
|
22
30
|
plain: "images/country-flags/flag-germany",
|
|
@@ -24,7 +32,7 @@ const countriesMap = {
|
|
|
24
32
|
}
|
|
25
33
|
},
|
|
26
34
|
pl: {
|
|
27
|
-
name: "
|
|
35
|
+
name: "Polish",
|
|
28
36
|
code: "pl",
|
|
29
37
|
flag: {
|
|
30
38
|
plain: "images/country-flags/flag-poland",
|
|
@@ -32,10 +40,10 @@ const countriesMap = {
|
|
|
32
40
|
}
|
|
33
41
|
}
|
|
34
42
|
};
|
|
35
|
-
export const
|
|
36
|
-
export function
|
|
37
|
-
return
|
|
43
|
+
export const languages = languagesMap;
|
|
44
|
+
export function getLanguage(code) {
|
|
45
|
+
return languages[code] ?? null;
|
|
38
46
|
}
|
|
39
|
-
export function
|
|
40
|
-
return Object.values(
|
|
47
|
+
export function getLanguages() {
|
|
48
|
+
return Object.values(languages);
|
|
41
49
|
}
|
package/dist/internal/types.d.ts
CHANGED
|
@@ -22,4 +22,15 @@ export type OpenMeteoResponse = {
|
|
|
22
22
|
temperature_2m_max: number[];
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
+
export type TranslateExists = (key: string) => boolean;
|
|
26
|
+
export type Translate = (key: string, params?: Record<string, unknown> | (string | number)[]) => string;
|
|
27
|
+
export type Route = {
|
|
28
|
+
name: string | symbol | undefined;
|
|
29
|
+
};
|
|
30
|
+
export type I18n = {
|
|
31
|
+
t: Translate;
|
|
32
|
+
$t: Translate;
|
|
33
|
+
te: TranslateExists;
|
|
34
|
+
$te: TranslateExists;
|
|
35
|
+
};
|
|
25
36
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC5B,OAAO,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,cAAc,EAAE,MAAM,CAAC;QACvB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,kBAAkB,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,MAAM,EAAE;QACJ,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,cAAc,EAAE,MAAM,EAAE,CAAC;QACzB,kBAAkB,EAAE,MAAM,EAAE,CAAC;QAC7B,kBAAkB,EAAE,MAAM,EAAE,CAAC;KAChC,CAAC;IACF,KAAK,EAAE;QACH,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,kBAAkB,EAAE,MAAM,EAAE,CAAC;QAC7B,kBAAkB,EAAE,MAAM,EAAE,CAAC;KAChC,CAAA;CACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC5B,OAAO,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,cAAc,EAAE,MAAM,CAAC;QACvB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,kBAAkB,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,MAAM,EAAE;QACJ,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,cAAc,EAAE,MAAM,EAAE,CAAC;QACzB,kBAAkB,EAAE,MAAM,EAAE,CAAC;QAC7B,kBAAkB,EAAE,MAAM,EAAE,CAAC;KAChC,CAAC;IACF,KAAK,EAAE;QACH,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,kBAAkB,EAAE,MAAM,EAAE,CAAC;QAC7B,kBAAkB,EAAE,MAAM,EAAE,CAAC;KAChC,CAAA;CACJ,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;AACvD,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,MAAM,CAAC;AAExG,MAAM,MAAM,KAAK,GAAG;IAChB,IAAI,EAAE,MAAM,GAAC,MAAM,GAAC,SAAS,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IACf,CAAC,EAAE,SAAS,CAAC;IACb,EAAE,EAAE,SAAS,CAAC;IACd,EAAE,EAAE,eAAe,CAAC;IACpB,GAAG,EAAE,eAAe,CAAC;CACxB,CAAC"}
|
package/dist/reload.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reload.d.ts","sourceRoot":"","sources":["../src/reload.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,cAAc,IAAI,CAE/B"}
|
package/dist/reload.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDarkTheme.d.ts","sourceRoot":"","sources":["../src/useDarkTheme.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAW,MAAM,EAAE,OAAO,GAAG,IAAI,CAE9C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Translate, TranslateExists } from './internal/types';
|
|
2
|
+
type I18nGlobal = {
|
|
3
|
+
t: Translate;
|
|
4
|
+
te: TranslateExists;
|
|
5
|
+
};
|
|
6
|
+
export declare function setGlobalI18n(i18n: I18nGlobal): void;
|
|
7
|
+
export declare function translate(key: string, params?: (Record<string, unknown> | (string | number)[])): string;
|
|
8
|
+
export declare function translationExists(key: string, subKeys?: string[]): boolean;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=vuei18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vuei18n.d.ts","sourceRoot":"","sources":["../src/vuei18n.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAElE,KAAK,UAAU,GAAG;IACd,CAAC,EAAE,SAAS,CAAC;IACb,EAAE,EAAE,eAAe,CAAC;CACvB,CAAA;AAID,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAEpD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAC,CAAC,MAAM,GAAC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CASnG;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,EAAO,GAAG,OAAO,CAW9E"}
|
package/dist/vuei18n.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import getVueInstance from './internal/getVueInstance';
|
|
2
|
+
let i18nGlobal = null;
|
|
3
|
+
export function setGlobalI18n(i18n) {
|
|
4
|
+
i18nGlobal = i18n;
|
|
5
|
+
}
|
|
6
|
+
export function translate(key, params) {
|
|
7
|
+
const { i18n } = getVueInstance();
|
|
8
|
+
const base = i18n?.$t ?? i18n?.t;
|
|
9
|
+
const fallback = i18nGlobal?.t ?? ((key) => key);
|
|
10
|
+
const method = base ?? fallback;
|
|
11
|
+
return method(key, params ?? {});
|
|
12
|
+
}
|
|
13
|
+
export function translationExists(key, subKeys = []) {
|
|
14
|
+
const { i18n } = getVueInstance();
|
|
15
|
+
const base = i18n?.$te ?? i18n?.te;
|
|
16
|
+
const fallback = i18nGlobal?.te ?? (() => false);
|
|
17
|
+
const method = base ?? fallback;
|
|
18
|
+
return subKeys.length === 0
|
|
19
|
+
? method(key)
|
|
20
|
+
: subKeys.every(subKey => method(`${key}.${subKey}`));
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@almighty-shogun/utils",
|
|
3
3
|
"description": "A small package that contains common utilities used in all my projects.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.8.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@types/luxon": "^3.7.1",
|
|
40
40
|
"luxon": "^3.7.2",
|
|
41
|
-
"vue
|
|
41
|
+
"vue": "^3.5.25"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { Weather, WeatherItem } from './internal/weather'
|
|
2
|
-
export {
|
|
2
|
+
export { getLanguage, getLanguages } from './internal/localization'
|
|
3
3
|
|
|
4
4
|
export { default as containsRoutePrefix } from './containsRoutePrefix'
|
|
5
5
|
export { default as disableZoom } from './disableZoom'
|
|
@@ -19,6 +19,11 @@ export { default as formatTime } from './formatTime'
|
|
|
19
19
|
export { default as formatWeekday } from './formatWeekday'
|
|
20
20
|
export { default as getWeather } from './getWeather'
|
|
21
21
|
export { default as hasCurrentRoute } from './hasCurrentRoute'
|
|
22
|
+
export { default as initApplication } from './initApplication'
|
|
22
23
|
export { default as isBeforeNow } from './isBeforeNow'
|
|
23
24
|
export { default as isCurrentRoute } from './isCurrentRoute'
|
|
25
|
+
export { default as reload } from './reload'
|
|
24
26
|
export { default as scrollToTop } from './scrollToTop'
|
|
27
|
+
export { default as useDarkTheme } from './useDarkTheme'
|
|
28
|
+
|
|
29
|
+
export * from './vuei18n'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import disableZoom from './disableZoom'
|
|
2
|
+
import useDarkTheme from './useDarkTheme'
|
|
3
|
+
|
|
4
|
+
type ApplicationConfig = {
|
|
5
|
+
locale?: string;
|
|
6
|
+
isDarkTheme?: boolean;
|
|
7
|
+
isZoomDisabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function (config: ApplicationConfig): void {
|
|
11
|
+
document.documentElement.setAttribute("lang", config.locale ?? "en");
|
|
12
|
+
|
|
13
|
+
useDarkTheme(config.isDarkTheme ?? false);
|
|
14
|
+
|
|
15
|
+
if (config.isZoomDisabled) {
|
|
16
|
+
disableZoom();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import getVueInstance from './getVueInstance'
|
|
2
2
|
|
|
3
3
|
export default function (): string {
|
|
4
|
-
const
|
|
4
|
+
const { route } = getVueInstance();
|
|
5
5
|
|
|
6
|
-
return
|
|
6
|
+
return route?.name?.toString() ?? "";
|
|
7
7
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getCurrentInstance } from 'vue'
|
|
2
|
+
import type { Route, I18n } from './types'
|
|
3
|
+
|
|
4
|
+
type VueInstance = {
|
|
5
|
+
i18n: I18n|null;
|
|
6
|
+
route: Route|null;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default function (): VueInstance {
|
|
10
|
+
const instance = getCurrentInstance();
|
|
11
|
+
const globalProperties = instance?.appContext.config.globalProperties;
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
i18n: globalProperties?.$i18n ?? null,
|
|
15
|
+
route: globalProperties?.$route ?? null,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type Language = {
|
|
2
2
|
name: string;
|
|
3
3
|
code: string;
|
|
4
4
|
flag: { plain: string; rounded: string; };
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
export type
|
|
8
|
-
export type LocalizationCountries = Record<
|
|
7
|
+
export type LanguageCode = keyof typeof languagesMap;
|
|
8
|
+
export type LocalizationCountries = Record<LanguageCode, Language>;
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const languagesMap: Record<string, Language> = {
|
|
11
|
+
en: {
|
|
12
|
+
name: "English",
|
|
13
|
+
code: "en",
|
|
14
|
+
flag: {
|
|
15
|
+
plain: "images/country-flags/flag-united-kingdom",
|
|
16
|
+
rounded: "images/country-flags/rounded/flag-united-kingdom",
|
|
17
|
+
}
|
|
18
|
+
},
|
|
11
19
|
nl: {
|
|
12
|
-
name: "
|
|
20
|
+
name: "Dutch",
|
|
13
21
|
code: "nl",
|
|
14
22
|
flag: {
|
|
15
23
|
plain: "images/country-flags/flag-netherlands",
|
|
@@ -17,7 +25,7 @@ const countriesMap: Record<string, Country> = {
|
|
|
17
25
|
}
|
|
18
26
|
},
|
|
19
27
|
fr: {
|
|
20
|
-
name: "
|
|
28
|
+
name: "French",
|
|
21
29
|
code: "fr",
|
|
22
30
|
flag: {
|
|
23
31
|
plain: "images/country-flags/flag-france",
|
|
@@ -25,7 +33,7 @@ const countriesMap: Record<string, Country> = {
|
|
|
25
33
|
}
|
|
26
34
|
},
|
|
27
35
|
de: {
|
|
28
|
-
name: "
|
|
36
|
+
name: "German",
|
|
29
37
|
code: "de",
|
|
30
38
|
flag: {
|
|
31
39
|
plain: "images/country-flags/flag-germany",
|
|
@@ -33,7 +41,7 @@ const countriesMap: Record<string, Country> = {
|
|
|
33
41
|
}
|
|
34
42
|
},
|
|
35
43
|
pl: {
|
|
36
|
-
name: "
|
|
44
|
+
name: "Polish",
|
|
37
45
|
code: "pl",
|
|
38
46
|
flag: {
|
|
39
47
|
plain: "images/country-flags/flag-poland",
|
|
@@ -42,12 +50,12 @@ const countriesMap: Record<string, Country> = {
|
|
|
42
50
|
}
|
|
43
51
|
};
|
|
44
52
|
|
|
45
|
-
export const
|
|
53
|
+
export const languages: LocalizationCountries = languagesMap as LocalizationCountries;
|
|
46
54
|
|
|
47
|
-
export function
|
|
48
|
-
return
|
|
55
|
+
export function getLanguage(code: LanguageCode): Language|null {
|
|
56
|
+
return languages[code] ?? null;
|
|
49
57
|
}
|
|
50
58
|
|
|
51
|
-
export function
|
|
52
|
-
return Object.values(
|
|
59
|
+
export function getLanguages(): Language[] {
|
|
60
|
+
return Object.values(languages);
|
|
53
61
|
}
|
package/src/internal/types.ts
CHANGED
|
@@ -22,3 +22,17 @@ export type OpenMeteoResponse = {
|
|
|
22
22
|
temperature_2m_max: number[];
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
+
|
|
26
|
+
export type TranslateExists = (key: string) => boolean;
|
|
27
|
+
export type Translate = (key: string, params?: Record<string, unknown> | (string | number)[]) => string;
|
|
28
|
+
|
|
29
|
+
export type Route = {
|
|
30
|
+
name: string|symbol|undefined;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type I18n = {
|
|
34
|
+
t: Translate;
|
|
35
|
+
$t: Translate;
|
|
36
|
+
te: TranslateExists;
|
|
37
|
+
$te: TranslateExists;
|
|
38
|
+
};
|
package/src/reload.ts
ADDED
package/src/vuei18n.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import getVueInstance from './internal/getVueInstance'
|
|
2
|
+
import type { Translate, TranslateExists } from './internal/types'
|
|
3
|
+
|
|
4
|
+
type I18nGlobal = {
|
|
5
|
+
t: Translate;
|
|
6
|
+
te: TranslateExists;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let i18nGlobal: I18nGlobal|null = null;
|
|
10
|
+
|
|
11
|
+
export function setGlobalI18n(i18n: I18nGlobal): void {
|
|
12
|
+
i18nGlobal = i18n;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function translate(key: string, params?: (Record<string, unknown>|(string|number)[])): string {
|
|
16
|
+
const { i18n } = getVueInstance();
|
|
17
|
+
|
|
18
|
+
const base = i18n?.$t ?? i18n?.t;
|
|
19
|
+
const fallback = i18nGlobal?.t ?? ((key) => key);
|
|
20
|
+
|
|
21
|
+
const method = base ?? fallback;
|
|
22
|
+
|
|
23
|
+
return method(key, params ?? {});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function translationExists(key: string, subKeys: string[] = []): boolean {
|
|
27
|
+
const { i18n } = getVueInstance();
|
|
28
|
+
|
|
29
|
+
const base = i18n?.$te ?? i18n?.te;
|
|
30
|
+
const fallback = i18nGlobal?.te ?? (() => false);
|
|
31
|
+
|
|
32
|
+
const method = base ?? fallback;
|
|
33
|
+
|
|
34
|
+
return subKeys.length === 0
|
|
35
|
+
? method(key)
|
|
36
|
+
: subKeys.every(subKey => method(`${key}.${subKey}`));
|
|
37
|
+
}
|