@empathyco/x-archetype-utils 0.1.0-alpha.10 → 0.1.0-alpha.12

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -1,35 +1,35 @@
1
- /**.
2
- * Self-made interface since Webpack does not provide a type for this object.
3
- * Https://github.com/webpack/webpack/blob/main/declarations/WebpackOptions.d.ts#L463
4
- *
5
- * @internal
6
- */
7
- interface webpackFilenameTemplateInfo {
8
- identifier: string;
9
- shortIdentifier: string;
10
- resource: string;
11
- resourcePath: string;
12
- absoluteResourcePath: string;
13
- allLoaders: string;
14
- query: string;
15
- moduleId: string;
16
- hash: string;
17
- namespace: string;
18
- }
19
- export declare const webpackConfig: {
20
- transpileDependencies: string[];
21
- configureWebpack: {
22
- module: {
23
- rules: {
24
- test: RegExp;
25
- enforce: string;
26
- use: string[];
27
- }[];
28
- };
29
- output: {
30
- devtoolModuleFilenameTemplate: ({ resourcePath, hash, query }: webpackFilenameTemplateInfo) => string;
31
- devtoolFallbackModuleFilenameTemplate: string;
32
- };
33
- };
34
- };
35
- export {};
1
+ /**.
2
+ * Self-made interface since Webpack does not provide a type for this object.
3
+ * Https://github.com/webpack/webpack/blob/main/declarations/WebpackOptions.d.ts#L463
4
+ *
5
+ * @internal
6
+ */
7
+ interface webpackFilenameTemplateInfo {
8
+ identifier: string;
9
+ shortIdentifier: string;
10
+ resource: string;
11
+ resourcePath: string;
12
+ absoluteResourcePath: string;
13
+ allLoaders: string;
14
+ query: string;
15
+ moduleId: string;
16
+ hash: string;
17
+ namespace: string;
18
+ }
19
+ export declare const webpackConfig: {
20
+ transpileDependencies: string[];
21
+ configureWebpack: {
22
+ module: {
23
+ rules: {
24
+ test: RegExp;
25
+ enforce: string;
26
+ use: string[];
27
+ }[];
28
+ };
29
+ output: {
30
+ devtoolModuleFilenameTemplate: ({ resourcePath, hash, query }: webpackFilenameTemplateInfo) => string;
31
+ devtoolFallbackModuleFilenameTemplate: string;
32
+ };
33
+ };
34
+ };
35
+ export {};
@@ -1,74 +1,74 @@
1
- import { VueConstructor } from 'vue';
2
- import VueI18n, { LocaleMessageObject } from 'vue-i18n';
3
- import { AnyMessages, Device, I18nOptions, Locale } from './i18n.types';
4
- /**
5
- * I18n settings manager.
6
- *
7
- * @public
8
- */
9
- export declare class I18n<SomeMessages> {
10
- vueI18n: VueI18n;
11
- protected locale: Locale;
12
- protected device: Device;
13
- protected messages: Record<Locale, AnyMessages<SomeMessages>>;
14
- protected currentMessages: LocaleMessageObject;
15
- protected fallbackLocale: Locale;
16
- /**
17
- * Constructs a new {@link I18n} instance with the passed {@link I18nOptions | i18n options}.
18
- *
19
- * @param options - The new {@link I18nOptions | i18n options}.
20
- */
21
- constructor({ locale, messages, device, fallbackLocale }: I18nOptions<SomeMessages>);
22
- /**
23
- * Creates a new {@link I18n} instance.
24
- *
25
- * @param options - The new {@link I18nOptions | i18n options}.
26
- *
27
- * @returns The new instance.
28
- */
29
- static create<SomeMessages>(options: I18nOptions<SomeMessages>): Promise<I18n<SomeMessages>>;
30
- /**
31
- * Installs VueI18n plugin.
32
- *
33
- * @param vue - The Vue instance.
34
- */
35
- install(vue: VueConstructor): void;
36
- /**
37
- * Tries to get a value from the messages object accessing it key by key.
38
- * When a key fails, takes the remaining key parts and tries to access the message
39
- * joining them into a single key.
40
- *
41
- * @param path - A dot separated key to access the message object.
42
- * @returns The message corresponding to the provided key, or empty string if it doesn't exist.
43
- */
44
- protected getMessageWithDotsInKey(path: string): string | null;
45
- /**
46
- * Sets the new locale and updates the messages accordingly.
47
- *
48
- * @param newLocale - The new locale.
49
- *
50
- * @returns The new messages.
51
- */
52
- setLocale(newLocale: Locale): Promise<void>;
53
- /**
54
- * Sets the new device and updates the messages accordingly.
55
- *
56
- * @param newDevice - The new device.
57
- *
58
- * @returns The new messages.
59
- */
60
- setDevice(newDevice: Device): Promise<void>;
61
- /**
62
- * Updates the current messages based on the new locale and/or device.
63
- */
64
- protected changeMessages(): Promise<void>;
65
- /**
66
- * Retrieves the corresponding messages for the set locale and device.
67
- *
68
- * @remarks By default, it merges `base` messages with the specific `device` ones. If there are
69
- * no messages for the current locale, the fallback locale is used instead.
70
- *
71
- * @returns The messages for the current locale and device.
72
- */
73
- protected getCurrentMessages(): Promise<LocaleMessageObject>;
74
- }
1
+ import { VueConstructor } from 'vue';
2
+ import VueI18n, { LocaleMessageObject } from 'vue-i18n';
3
+ import { AnyMessages, Device, I18nOptions, Locale } from './i18n.types';
4
+ /**
5
+ * I18n settings manager.
6
+ *
7
+ * @public
8
+ */
9
+ export declare class I18n<SomeMessages> {
10
+ vueI18n: VueI18n;
11
+ protected locale: Locale;
12
+ protected device: Device;
13
+ protected messages: Record<Locale, AnyMessages<SomeMessages>>;
14
+ protected currentMessages: LocaleMessageObject;
15
+ protected fallbackLocale: Locale;
16
+ /**
17
+ * Constructs a new {@link I18n} instance with the passed {@link I18nOptions | i18n options}.
18
+ *
19
+ * @param options - The new {@link I18nOptions | i18n options}.
20
+ */
21
+ constructor({ locale, messages, device, fallbackLocale }: I18nOptions<SomeMessages>);
22
+ /**
23
+ * Creates a new {@link I18n} instance.
24
+ *
25
+ * @param options - The new {@link I18nOptions | i18n options}.
26
+ *
27
+ * @returns The new instance.
28
+ */
29
+ static create<SomeMessages>(options: I18nOptions<SomeMessages>): Promise<I18n<SomeMessages>>;
30
+ /**
31
+ * Installs VueI18n plugin.
32
+ *
33
+ * @param vue - The Vue instance.
34
+ */
35
+ install(vue: VueConstructor): void;
36
+ /**
37
+ * Tries to get a value from the messages object accessing it key by key.
38
+ * When a key fails, takes the remaining key parts and tries to access the message
39
+ * joining them into a single key.
40
+ *
41
+ * @param path - A dot separated key to access the message object.
42
+ * @returns The message corresponding to the provided key, or empty string if it doesn't exist.
43
+ */
44
+ protected getMessageWithDotsInKey(path: string): string | null;
45
+ /**
46
+ * Sets the new locale and updates the messages accordingly.
47
+ *
48
+ * @param newLocale - The new locale.
49
+ *
50
+ * @returns The new messages.
51
+ */
52
+ setLocale(newLocale: Locale): Promise<void>;
53
+ /**
54
+ * Sets the new device and updates the messages accordingly.
55
+ *
56
+ * @param newDevice - The new device.
57
+ *
58
+ * @returns The new messages.
59
+ */
60
+ setDevice(newDevice: Device): Promise<void>;
61
+ /**
62
+ * Updates the current messages based on the new locale and/or device.
63
+ */
64
+ protected changeMessages(): Promise<void>;
65
+ /**
66
+ * Retrieves the corresponding messages for the set locale and device.
67
+ *
68
+ * @remarks By default, it merges `base` messages with the specific `device` ones. If there are
69
+ * no messages for the current locale, the fallback locale is used instead.
70
+ *
71
+ * @returns The messages for the current locale and device.
72
+ */
73
+ protected getCurrentMessages(): Promise<LocaleMessageObject>;
74
+ }
@@ -1,53 +1,53 @@
1
- import VueI18n from 'vue-i18n';
2
- import { DeepPartial } from '@empathyco/x-utils';
3
- /** Supported locales. */
4
- export declare type Locale = string;
5
- /** Supported devices. */
6
- export declare type Device = string;
7
- /** Union type containing both eager and lazy messages. */
8
- export declare type AnyMessages<SomeMessages> = MessagesByDevice<SomeMessages> | LoadLazyMessagesByDevice<SomeMessages>;
9
- /** A function that loads on demand the messages for a specific locale. */
10
- export declare type LoadLazyMessagesByDevice<SomeMessages> = () => Promise<{
11
- default: MessagesByDevice<SomeMessages>;
12
- }>;
13
- /**
14
- * An object containing a base property with all the existing messages and the overridden ones for
15
- * each device.
16
- */
17
- export interface MessagesByDevice<SomeMessages> {
18
- base: SomeMessages;
19
- [device: Device]: DeepPartial<SomeMessages>;
20
- }
21
- /**
22
- * I18n settings.
23
- */
24
- export interface I18nOptions<SomeMessages> {
25
- /** The initial messages. */
26
- messages: Record<Locale, AnyMessages<SomeMessages>>;
27
- /** The initial device. */
28
- device: Device;
29
- /** The locale to fall back if no matching locale is available. */
30
- fallbackLocale: Locale;
31
- /** The initial locale. */
32
- locale: Locale;
33
- }
34
- /**
35
- * The VueI18n instance that should be passed to the root Vue instance and some runtime utility
36
- * functions.
37
- */
38
- export interface I18nAPI {
39
- /** The Vue I18n instance that should be passed to the root Vue component. */
40
- readonly vueI18n: Readonly<VueI18n>;
41
- /**
42
- * Sets the new locale.
43
- *
44
- * @param newLocale - The new locale.
45
- */
46
- setLocale: (newLocale: Locale) => Promise<void>;
47
- /**
48
- * Sets the new device.
49
- *
50
- * @param newDevice - The new device.
51
- */
52
- setDevice: (newDevice: Device) => Promise<void>;
53
- }
1
+ import VueI18n from 'vue-i18n';
2
+ import { DeepPartial } from '@empathyco/x-utils';
3
+ /** Supported locales. */
4
+ export declare type Locale = string;
5
+ /** Supported devices. */
6
+ export declare type Device = string;
7
+ /** Union type containing both eager and lazy messages. */
8
+ export declare type AnyMessages<SomeMessages> = MessagesByDevice<SomeMessages> | LoadLazyMessagesByDevice<SomeMessages>;
9
+ /** A function that loads on demand the messages for a specific locale. */
10
+ export declare type LoadLazyMessagesByDevice<SomeMessages> = () => Promise<{
11
+ default: MessagesByDevice<SomeMessages>;
12
+ }>;
13
+ /**
14
+ * An object containing a base property with all the existing messages and the overridden ones for
15
+ * each device.
16
+ */
17
+ export interface MessagesByDevice<SomeMessages> {
18
+ base: SomeMessages;
19
+ [device: Device]: DeepPartial<SomeMessages>;
20
+ }
21
+ /**
22
+ * I18n settings.
23
+ */
24
+ export interface I18nOptions<SomeMessages> {
25
+ /** The initial messages. */
26
+ messages: Record<Locale, AnyMessages<SomeMessages>>;
27
+ /** The initial device. */
28
+ device: Device;
29
+ /** The locale to fall back if no matching locale is available. */
30
+ fallbackLocale: Locale;
31
+ /** The initial locale. */
32
+ locale: Locale;
33
+ }
34
+ /**
35
+ * The VueI18n instance that should be passed to the root Vue instance and some runtime utility
36
+ * functions.
37
+ */
38
+ export interface I18nAPI {
39
+ /** The Vue I18n instance that should be passed to the root Vue component. */
40
+ readonly vueI18n: Readonly<VueI18n>;
41
+ /**
42
+ * Sets the new locale.
43
+ *
44
+ * @param newLocale - The new locale.
45
+ */
46
+ setLocale: (newLocale: Locale) => Promise<void>;
47
+ /**
48
+ * Sets the new device.
49
+ *
50
+ * @param newDevice - The new device.
51
+ */
52
+ setDevice: (newDevice: Device) => Promise<void>;
53
+ }
@@ -1,3 +1,3 @@
1
- export * from './i18n/i18n.plugin';
2
- export * from './i18n/i18n.types';
3
- export * from './build/webpack/webpack.config';
1
+ export * from './i18n/i18n.plugin';
2
+ export * from './i18n/i18n.types';
3
+ export * from './build/webpack/webpack.config';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empathyco/x-archetype-utils",
3
- "version": "0.1.0-alpha.10",
3
+ "version": "0.1.0-alpha.12",
4
4
  "description": "Utilities for x-archetype",
5
5
  "author": "Empathy Systems Corporation S.L.",
6
6
  "license": "Apache-2.0",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "scripts": {
28
28
  "prebuild": "rimraf dist ./*.tgz",
29
- "build": "concurrently \"npm run build:*\"",
29
+ "build": "rollup -c",
30
30
  "build:cjs": "tsc --project tsconfig.cjs.json",
31
31
  "build:esm": "tsc --project tsconfig.esm.json",
32
32
  "postbuild": "npm pack",
@@ -42,8 +42,11 @@
42
42
  "@types/jest": "~27.0.3",
43
43
  "@types/node": "~16.4.12",
44
44
  "@vue/test-utils": "~1.0.3",
45
- "concurrently": "~7.6.0",
46
45
  "jest": "~27.3.1",
46
+ "rollup": "~2.79.1",
47
+ "rollup-plugin-copy": "~3.4.0",
48
+ "rollup-plugin-delete": "~2.0.0",
49
+ "rollup-plugin-typescript2": "~0.31.2",
47
50
  "ts-jest": "~27.0.7",
48
51
  "typescript": "~4.6.2",
49
52
  "vue": "~2.7.14"
@@ -55,5 +58,5 @@
55
58
  "publishConfig": {
56
59
  "access": "public"
57
60
  },
58
- "gitHead": "9a571e850e671c1227d17db9b574579a8a8464ae"
61
+ "gitHead": "0eba276809351f9a2841ee5a34d468a05c2ca14f"
59
62
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"webpack.config.js","sourceRoot":"","sources":["../../../../src/build/webpack/webpack.config.ts"],"names":[],"mappings":";;;AAmBa,QAAA,aAAa,GAAG;IAC3B,qBAAqB,EAAE,CAAC,yBAAyB,CAAC;IAClD,gBAAgB,EAAE;QAChB,MAAM,EAAE;YACN,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE,KAAK;oBACd,GAAG,EAAE,CAAC,mBAAmB,CAAC;iBAC3B;aACF;SACF;QACD,MAAM,EAAE;YACN,6BAA6B,EAAE,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAA+B,EAAE,EAAE,CAC5F,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC;gBAC5B,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC;gBAC3B,CAAC,KAAK,CAAC,KAAK,CAAC,+BAA+B,CAAC;gBAC3C,CAAC,CAAC,wBAAwB,YAAY,IAAI,IAAI,EAAE;gBAChD,CAAC,CAAC,aAAa,YAAY,EAAE;YACjC,qCAAqC,EAAE,mCAAmC;SAC3E;KACF;CACF,CAAC","sourcesContent":["/**.\n * Self-made interface since Webpack does not provide a type for this object.\n * Https://github.com/webpack/webpack/blob/main/declarations/WebpackOptions.d.ts#L463\n *\n * @internal\n */\ninterface webpackFilenameTemplateInfo {\n identifier: string;\n shortIdentifier: string;\n resource: string;\n resourcePath: string;\n absoluteResourcePath: string;\n allLoaders: string;\n query: string;\n moduleId: string;\n hash: string;\n namespace: string;\n}\n\nexport const webpackConfig = {\n transpileDependencies: ['@empathyco/x-components'],\n configureWebpack: {\n module: {\n rules: [\n {\n test: /\\.ts|js|vue$/,\n enforce: 'pre',\n use: ['source-map-loader']\n }\n ]\n },\n output: {\n devtoolModuleFilenameTemplate: ({ resourcePath, hash, query }: webpackFilenameTemplateInfo) =>\n resourcePath.match(/\\.vue$/) &&\n !query.match(/type=script/) &&\n !query.match(/\\?rollup-plugin-vue=script.ts/)\n ? `webpack-generated:///${resourcePath}?${hash}`\n : `sources://${resourcePath}`,\n devtoolFallbackModuleFilenameTemplate: 'webpack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AC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;IACnE,CAAC;IAED;;;;;;;OAOG;IACO,KAAK,CAAC,kBAAkB;QAChC,MAAM,WAAW,GACf,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ;YAC1B,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;YAC5B,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAEzC,MAAM,QAAQ,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC;QAC5F,6DAA6D;QAC7D,OAAO,IAAA,wBAAS,EAAC,EAAE,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7D,CAAC;CACF;AAvID,oBAuIC;AAED;;;;;;GAMG;AACH,SAAS,eAAe,CACtB,QAAmC;IAEnC,OAAO,OAAO,QAAQ,KAAK,UAAU,CAAC;AACxC,CAAC","sourcesContent":["import { isObject } from '@empathyco/x-utils';\nimport { VueConstructor } from 'vue';\nimport VueI18n, { LocaleMessageObject, LocaleMessage } from 'vue-i18n';\nimport { deepMerge } from '@empathyco/x-deep-merge';\nimport { AnyMessages, Device, I18nOptions, LoadLazyMessagesByDevice, Locale } from './i18n.types';\n\n/**\n * I18n settings manager.\n *\n * @public\n */\nexport class I18n<SomeMessages> {\n public vueI18n!: VueI18n;\n protected locale!: Locale;\n protected device!: Device;\n protected messages!: Record<Locale, AnyMessages<SomeMessages>>;\n protected currentMessages!: LocaleMessageObject;\n protected fallbackLocale!: Locale;\n\n /**\n * Constructs a new {@link I18n} instance with the passed {@link I18nOptions | i18n options}.\n *\n * @param options - The new {@link I18nOptions | i18n options}.\n */\n public constructor({ locale, messages, device, fallbackLocale }: I18nOptions<SomeMessages>) {\n this.locale = locale;\n this.device = device;\n this.messages = messages;\n this.fallbackLocale = fallbackLocale;\n }\n\n /**\n * Creates a new {@link I18n} instance.\n *\n * @param options - The new {@link I18nOptions | i18n options}.\n *\n * @returns The new instance.\n */\n static async create<SomeMessages>(\n options: I18nOptions<SomeMessages>\n ): Promise<I18n<SomeMessages>> {\n const instance = new I18n(options);\n instance.currentMessages = await instance.getCurrentMessages();\n return instance;\n }\n\n /**\n * Installs VueI18n plugin.\n *\n * @param vue - The Vue instance.\n */\n install(vue: VueConstructor): void {\n vue.use(VueI18n);\n this.vueI18n = new VueI18n({\n locale: this.locale,\n messages: this.currentMessages ? { [this.locale]: this.currentMessages } : {},\n silentFallbackWarn: true,\n missing: (locale, key) => {\n return (\n this.getMessageWithDotsInKey(key) ??\n `[i18n] Key '${key}' is missing for locale: '${locale}'`\n );\n }\n });\n }\n\n /**\n * Tries to get a value from the messages object accessing it key by key.\n * When a key fails, takes the remaining key parts and tries to access the message\n * joining them into a single key.\n *\n * @param path - A dot separated key to access the message object.\n * @returns The message corresponding to the provided key, or empty string if it doesn't exist.\n */\n protected getMessageWithDotsInKey(path: string): string | null {\n // TO-DO Support function or array messages\n const message = path\n .split('.')\n .reduce<LocaleMessage>(\n (messages, key, index, pathParts) =>\n isObject(messages)\n ? messages[key] ?? messages[pathParts.slice(index).join('.')]\n : messages,\n this.currentMessages\n );\n return typeof message === 'string' ? message : null;\n }\n\n /**\n * Sets the new locale and updates the messages accordingly.\n *\n * @param newLocale - The new locale.\n *\n * @returns The new messages.\n */\n async setLocale(newLocale: Locale): Promise<void> {\n if (this.locale !== newLocale) {\n this.locale = newLocale;\n\n await this.changeMessages();\n this.vueI18n.locale = this.locale;\n }\n }\n\n /**\n * Sets the new device and updates the messages accordingly.\n *\n * @param newDevice - The new device.\n *\n * @returns The new messages.\n */\n async setDevice(newDevice: Device): Promise<void> {\n if (this.device !== newDevice) {\n this.device = newDevice;\n\n await this.changeMessages();\n }\n }\n\n /**\n * Updates the current messages based on the new locale and/or device.\n */\n protected async changeMessages(): Promise<void> {\n this.currentMessages = await this.getCurrentMessages();\n\n this.vueI18n.setLocaleMessage(this.locale, this.currentMessages);\n }\n\n /**\n * Retrieves the corresponding messages for the set locale and device.\n *\n * @remarks By default, it merges `base` messages with the specific `device` ones. If there are\n * no messages for the current locale, the fallback locale is used instead.\n *\n * @returns The messages for the current locale and device.\n */\n protected async getCurrentMessages(): Promise<LocaleMessageObject> {\n const rawMessages =\n this.locale in this.messages\n ? this.messages[this.locale]\n : this.messages[this.fallbackLocale];\n\n const messages = areLazyMessages(rawMessages) ? (await rawMessages()).default : rawMessages;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n return deepMerge({}, messages.base, messages[this.device]);\n }\n}\n\n/**\n * Type-guard to check if the passed messages should be lazy-loaded.\n *\n * @param messages - The messages to check.\n *\n * @returns True if the messages are lazy or false otherwise.\n */\nfunction areLazyMessages<SomeMessages>(\n messages: AnyMessages<SomeMessages>\n): messages is LoadLazyMessagesByDevice<SomeMessages> {\n return typeof messages === 'function';\n}\n"]}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=i18n.types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"i18n.types.js","sourceRoot":"","sources":["../../../src/i18n/i18n.types.ts"],"names":[],"mappings":"","sourcesContent":["import VueI18n from 'vue-i18n';\nimport { DeepPartial } from '@empathyco/x-utils';\n\n/** Supported locales. */\nexport type Locale = string;\n\n/** Supported devices. */\nexport type Device = string;\n\n/** Union type containing both eager and lazy messages. */\nexport type AnyMessages<SomeMessages> =\n | MessagesByDevice<SomeMessages>\n | LoadLazyMessagesByDevice<SomeMessages>;\n\n/** A function that loads on demand the messages for a specific locale. */\nexport type LoadLazyMessagesByDevice<SomeMessages> = () => Promise<{\n default: MessagesByDevice<SomeMessages>;\n}>;\n\n/**\n * An object containing a base property with all the existing messages and the overridden ones for\n * each device.\n */\nexport interface MessagesByDevice<SomeMessages> {\n base: SomeMessages;\n [device: Device]: DeepPartial<SomeMessages>;\n}\n\n/**\n * I18n settings.\n */\nexport interface I18nOptions<SomeMessages> {\n /** The initial messages. */\n messages: Record<Locale, AnyMessages<SomeMessages>>;\n /** The initial device. */\n device: Device;\n /** The locale to fall back if no matching locale is available. */\n fallbackLocale: Locale;\n /** The initial locale. */\n locale: Locale;\n}\n\n/**\n * The VueI18n instance that should be passed to the root Vue instance and some runtime utility\n * functions.\n */\nexport interface I18nAPI {\n /** The Vue I18n instance that should be passed to the root Vue component. */\n readonly vueI18n: Readonly<VueI18n>;\n /**\n * Sets the new locale.\n *\n * @param newLocale - The new locale.\n */\n setLocale: (newLocale: Locale) => Promise<void>;\n /**\n * Sets the new device.\n *\n * @param newDevice - The new device.\n */\n setDevice: (newDevice: Device) => Promise<void>;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,4DAAkC;AAClC,yEAA+C","sourcesContent":["export * from './i18n/i18n.plugin';\nexport * from './i18n/i18n.types';\nexport * from './build/webpack/webpack.config';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"webpack.config.js","sourceRoot":"","sources":["../../../../src/build/webpack/webpack.config.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,qBAAqB,EAAE,CAAC,yBAAyB,CAAC;IAClD,gBAAgB,EAAE;QAChB,MAAM,EAAE;YACN,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE,KAAK;oBACd,GAAG,EAAE,CAAC,mBAAmB,CAAC;iBAC3B;aACF;SACF;QACD,MAAM,EAAE;YACN,6BAA6B,EAAE,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAA+B,EAAE,EAAE,CAC5F,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC;gBAC5B,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC;gBAC3B,CAAC,KAAK,CAAC,KAAK,CAAC,+BAA+B,CAAC;gBAC3C,CAAC,CAAC,wBAAwB,YAAY,IAAI,IAAI,EAAE;gBAChD,CAAC,CAAC,aAAa,YAAY,EAAE;YACjC,qCAAqC,EAAE,mCAAmC;SAC3E;KACF;CACF,CAAC","sourcesContent":["/**.\n * Self-made interface since Webpack does not provide a type for this object.\n * Https://github.com/webpack/webpack/blob/main/declarations/WebpackOptions.d.ts#L463\n *\n * @internal\n */\ninterface webpackFilenameTemplateInfo {\n identifier: string;\n shortIdentifier: string;\n resource: string;\n resourcePath: string;\n absoluteResourcePath: string;\n allLoaders: string;\n query: string;\n moduleId: string;\n hash: string;\n namespace: string;\n}\n\nexport const webpackConfig = {\n transpileDependencies: ['@empathyco/x-components'],\n configureWebpack: {\n module: {\n rules: [\n {\n test: /\\.ts|js|vue$/,\n enforce: 'pre',\n use: ['source-map-loader']\n }\n ]\n },\n output: {\n devtoolModuleFilenameTemplate: ({ resourcePath, hash, query }: webpackFilenameTemplateInfo) =>\n resourcePath.match(/\\.vue$/) &&\n !query.match(/type=script/) &&\n !query.match(/\\?rollup-plugin-vue=script.ts/)\n ? `webpack-generated:///${resourcePath}?${hash}`\n : `sources://${resourcePath}`,\n devtoolFallbackModuleFilenameTemplate: 'webpack:///[resource-path]?[hash]'\n }\n }\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"i18n.plugin.js","sourceRoot":"","sources":["../../../src/i18n/i18n.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,OAA+C,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD;;;;GAIG;AACH,MAAM,OAAO,IAAI;IAQf;;;;OAIG;IACH,YAAmB,EAAE,MAAM,EAAE,QAAQ,EAAE,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,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAEzC,MAAM,QAAQ,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC;QAC5F,6DAA6D;QAC7D,OAAO,SAAS,CAAC,EAAE,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7D,CAAC;CACF;AAED;;;;;;GAMG;AACH,SAAS,eAAe,CACtB,QAAmC;IAEnC,OAAO,OAAO,QAAQ,KAAK,UAAU,CAAC;AACxC,CAAC","sourcesContent":["import { isObject } from '@empathyco/x-utils';\nimport { VueConstructor } from 'vue';\nimport VueI18n, { LocaleMessageObject, LocaleMessage } from 'vue-i18n';\nimport { deepMerge } from '@empathyco/x-deep-merge';\nimport { AnyMessages, Device, I18nOptions, LoadLazyMessagesByDevice, Locale } from './i18n.types';\n\n/**\n * I18n settings manager.\n *\n * @public\n */\nexport class I18n<SomeMessages> {\n public vueI18n!: VueI18n;\n protected locale!: Locale;\n protected device!: Device;\n protected messages!: Record<Locale, AnyMessages<SomeMessages>>;\n protected currentMessages!: LocaleMessageObject;\n protected fallbackLocale!: Locale;\n\n /**\n * Constructs a new {@link I18n} instance with the passed {@link I18nOptions | i18n options}.\n *\n * @param options - The new {@link I18nOptions | i18n options}.\n */\n public constructor({ locale, messages, device, fallbackLocale }: I18nOptions<SomeMessages>) {\n this.locale = locale;\n this.device = device;\n this.messages = messages;\n this.fallbackLocale = fallbackLocale;\n }\n\n /**\n * Creates a new {@link I18n} instance.\n *\n * @param options - The new {@link I18nOptions | i18n options}.\n *\n * @returns The new instance.\n */\n static async create<SomeMessages>(\n options: I18nOptions<SomeMessages>\n ): Promise<I18n<SomeMessages>> {\n const instance = new I18n(options);\n instance.currentMessages = await instance.getCurrentMessages();\n return instance;\n }\n\n /**\n * Installs VueI18n plugin.\n *\n * @param vue - The Vue instance.\n */\n install(vue: VueConstructor): void {\n vue.use(VueI18n);\n this.vueI18n = new VueI18n({\n locale: this.locale,\n messages: this.currentMessages ? { [this.locale]: this.currentMessages } : {},\n silentFallbackWarn: true,\n missing: (locale, key) => {\n return (\n this.getMessageWithDotsInKey(key) ??\n `[i18n] Key '${key}' is missing for locale: '${locale}'`\n );\n }\n });\n }\n\n /**\n * Tries to get a value from the messages object accessing it key by key.\n * When a key fails, takes the remaining key parts and tries to access the message\n * joining them into a single key.\n *\n * @param path - A dot separated key to access the message object.\n * @returns The message corresponding to the provided key, or empty string if it doesn't exist.\n */\n protected getMessageWithDotsInKey(path: string): string | null {\n // TO-DO Support function or array messages\n const message = path\n .split('.')\n .reduce<LocaleMessage>(\n (messages, key, index, pathParts) =>\n isObject(messages)\n ? messages[key] ?? messages[pathParts.slice(index).join('.')]\n : messages,\n this.currentMessages\n );\n return typeof message === 'string' ? message : null;\n }\n\n /**\n * Sets the new locale and updates the messages accordingly.\n *\n * @param newLocale - The new locale.\n *\n * @returns The new messages.\n */\n async setLocale(newLocale: Locale): Promise<void> {\n if (this.locale !== newLocale) {\n this.locale = newLocale;\n\n await this.changeMessages();\n this.vueI18n.locale = this.locale;\n }\n }\n\n /**\n * Sets the new device and updates the messages accordingly.\n *\n * @param newDevice - The new device.\n *\n * @returns The new messages.\n */\n async setDevice(newDevice: Device): Promise<void> {\n if (this.device !== newDevice) {\n this.device = newDevice;\n\n await this.changeMessages();\n }\n }\n\n /**\n * Updates the current messages based on the new locale and/or device.\n */\n protected async changeMessages(): Promise<void> {\n this.currentMessages = await this.getCurrentMessages();\n\n this.vueI18n.setLocaleMessage(this.locale, this.currentMessages);\n }\n\n /**\n * Retrieves the corresponding messages for the set locale and device.\n *\n * @remarks By default, it merges `base` messages with the specific `device` ones. If there are\n * no messages for the current locale, the fallback locale is used instead.\n *\n * @returns The messages for the current locale and device.\n */\n protected async getCurrentMessages(): Promise<LocaleMessageObject> {\n const rawMessages =\n this.locale in this.messages\n ? this.messages[this.locale]\n : this.messages[this.fallbackLocale];\n\n const messages = areLazyMessages(rawMessages) ? (await rawMessages()).default : rawMessages;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n return deepMerge({}, messages.base, messages[this.device]);\n }\n}\n\n/**\n * Type-guard to check if the passed messages should be lazy-loaded.\n *\n * @param messages - The messages to check.\n *\n * @returns True if the messages are lazy or false otherwise.\n */\nfunction areLazyMessages<SomeMessages>(\n messages: AnyMessages<SomeMessages>\n): messages is LoadLazyMessagesByDevice<SomeMessages> {\n return typeof messages === 'function';\n}\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=i18n.types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"i18n.types.js","sourceRoot":"","sources":["../../../src/i18n/i18n.types.ts"],"names":[],"mappings":"","sourcesContent":["import VueI18n from 'vue-i18n';\nimport { DeepPartial } from '@empathyco/x-utils';\n\n/** Supported locales. */\nexport type Locale = string;\n\n/** Supported devices. */\nexport type Device = string;\n\n/** Union type containing both eager and lazy messages. */\nexport type AnyMessages<SomeMessages> =\n | MessagesByDevice<SomeMessages>\n | LoadLazyMessagesByDevice<SomeMessages>;\n\n/** A function that loads on demand the messages for a specific locale. */\nexport type LoadLazyMessagesByDevice<SomeMessages> = () => Promise<{\n default: MessagesByDevice<SomeMessages>;\n}>;\n\n/**\n * An object containing a base property with all the existing messages and the overridden ones for\n * each device.\n */\nexport interface MessagesByDevice<SomeMessages> {\n base: SomeMessages;\n [device: Device]: DeepPartial<SomeMessages>;\n}\n\n/**\n * I18n settings.\n */\nexport interface I18nOptions<SomeMessages> {\n /** The initial messages. */\n messages: Record<Locale, AnyMessages<SomeMessages>>;\n /** The initial device. */\n device: Device;\n /** The locale to fall back if no matching locale is available. */\n fallbackLocale: Locale;\n /** The initial locale. */\n locale: Locale;\n}\n\n/**\n * The VueI18n instance that should be passed to the root Vue instance and some runtime utility\n * functions.\n */\nexport interface I18nAPI {\n /** The Vue I18n instance that should be passed to the root Vue component. */\n readonly vueI18n: Readonly<VueI18n>;\n /**\n * Sets the new locale.\n *\n * @param newLocale - The new locale.\n */\n setLocale: (newLocale: Locale) => Promise<void>;\n /**\n * Sets the new device.\n *\n * @param newDevice - The new device.\n */\n setDevice: (newDevice: Device) => Promise<void>;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC","sourcesContent":["export * from './i18n/i18n.plugin';\nexport * from './i18n/i18n.types';\nexport * from './build/webpack/webpack.config';\n"]}