sprintify-ui 0.1.15 → 0.1.16
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/README.md +1 -26
- package/dist/sprintify-ui.es.js +11935 -11825
- package/dist/style.css +1 -1
- package/dist/types/src/components/BaseAutocomplete.vue.d.ts +1 -1
- package/dist/types/src/components/BaseAutocompleteFetch.vue.d.ts +2 -2
- package/dist/types/src/components/BaseBelongsTo.vue.d.ts +1 -1
- package/dist/types/src/components/BaseDatePicker.vue.d.ts +1 -1
- package/dist/types/src/components/BaseFileUploader.vue.d.ts +1 -1
- package/dist/types/src/components/BaseHeader.vue.d.ts +1 -1
- package/dist/types/src/components/BaseMediaLibrary.vue.d.ts +1 -1
- package/dist/types/src/components/BaseMediaListItem.vue.d.ts +1 -1
- package/dist/types/src/components/BaseNumber.vue.d.ts +3 -3
- package/dist/types/src/components/BaseTableColumn.vue.d.ts +1 -1
- package/dist/types/src/components/BaseTagAutocomplete.vue.d.ts +1 -1
- package/dist/types/src/composables/mediaQuery.d.ts +2 -2
- package/dist/types/src/i18n/index.d.ts +1 -0
- package/dist/types/src/index.d.ts +0 -178
- package/dist/types/src/stores/i18n.d.ts +5 -0
- package/package.json +7 -6
- package/src/components/BaseAddressForm.vue +8 -7
- package/src/components/BaseAutocomplete.vue +3 -3
- package/src/components/BaseAutocompleteDrawer.vue +2 -1
- package/src/components/BaseAutocompleteFetch.vue +2 -1
- package/src/components/BaseCharacterCounter.vue +2 -1
- package/src/components/BaseClipboard.vue +4 -2
- package/src/components/BaseCropper.vue +2 -5
- package/src/components/BaseCropperModal.vue +3 -2
- package/src/components/BaseDataIterator.vue +6 -7
- package/src/components/BaseDataTable.vue +14 -14
- package/src/components/BaseDatePicker.vue +4 -4
- package/src/components/BaseDateSelect.vue +10 -10
- package/src/components/BaseDialog.vue +5 -6
- package/src/components/BaseDisplayRelativeTime.vue +6 -6
- package/src/components/BaseFilePicker.vue +7 -8
- package/src/components/BaseFileUploader.vue +3 -3
- package/src/components/BaseForm.vue +3 -3
- package/src/components/BaseIconPicker.vue +2 -1
- package/src/components/BaseLayoutNotificationDropdown.vue +3 -2
- package/src/components/BaseMediaLibrary.vue +8 -11
- package/src/components/BaseMediaListItem.vue +4 -3
- package/src/components/BaseNumber.vue +25 -5
- package/src/components/BasePagination.vue +4 -3
- package/src/components/BaseReadMore.vue +2 -1
- package/src/components/BaseSelect.vue +3 -2
- package/src/components/BaseTagAutocomplete.vue +4 -4
- package/src/components/BaseTagAutocompleteFetch.vue +3 -2
- package/src/composables/mediaQuery.ts +2 -2
- package/src/i18n/index.ts +60 -0
- package/src/index.ts +11 -11
- package/src/stores/dialogs.ts +3 -3
- package/src/stores/i18n.ts +14 -0
- package/src/utils/fileSizeFormat.ts +6 -6
- package/src/utils/toHumanList.ts +2 -2
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useI18nStore } from '@/stores/i18n';
|
|
2
|
+
import en from '@/lang/en.json';
|
|
3
|
+
import fr from '@/lang/fr.json';
|
|
4
|
+
import { get } from 'lodash';
|
|
5
|
+
|
|
6
|
+
export function t(key: string, args?: Record<string, any> | undefined): string {
|
|
7
|
+
const value = getTranslationValue(key);
|
|
8
|
+
|
|
9
|
+
return replaceArgs(value, args);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getCurrentLocale() {
|
|
13
|
+
try {
|
|
14
|
+
const i18nStore = useI18nStore();
|
|
15
|
+
return i18nStore.locale;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error(error);
|
|
18
|
+
return 'en';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getTranslationValue(key: string) {
|
|
23
|
+
const locale = getCurrentLocale();
|
|
24
|
+
|
|
25
|
+
if (locale === 'fr') {
|
|
26
|
+
const frValue = get(fr, key);
|
|
27
|
+
if (frValue) return frValue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return get(en, key, key);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function replaceArgs(
|
|
34
|
+
value: string,
|
|
35
|
+
args: Record<string, any> | undefined
|
|
36
|
+
): string {
|
|
37
|
+
let result = value;
|
|
38
|
+
|
|
39
|
+
if (!args) return result;
|
|
40
|
+
|
|
41
|
+
if (args.count !== undefined && value.includes('|')) {
|
|
42
|
+
const parts = value.split('|');
|
|
43
|
+
|
|
44
|
+
if (parts.length == 2) {
|
|
45
|
+
const [singular, plural] = value.split('|');
|
|
46
|
+
result = args.count > 1 ? plural : singular;
|
|
47
|
+
} else if (parts.length == 3) {
|
|
48
|
+
const [zero, singular, plural] = value.split('|');
|
|
49
|
+
result = args.count == 0 ? zero : args.count > 1 ? plural : singular;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
result.trim();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Object.keys(args).forEach((key: any) => {
|
|
56
|
+
result = result.replace(`{${key}}`, args[key]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return result;
|
|
60
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,6 @@ import axios, { AxiosInstance } from 'axios';
|
|
|
2
2
|
import { App } from 'vue';
|
|
3
3
|
import * as components from './components';
|
|
4
4
|
import QueryString from 'qs';
|
|
5
|
-
import { createI18n, I18n } from 'vue-i18n';
|
|
6
5
|
import en from '@/lang/en.json';
|
|
7
6
|
import fr from '@/lang/fr.json';
|
|
8
7
|
import { useDialogsStore } from './stores/dialogs';
|
|
@@ -17,10 +16,10 @@ import './assets/main.css';
|
|
|
17
16
|
import { Locales } from './types';
|
|
18
17
|
import { Country } from './types/Country';
|
|
19
18
|
import { Region } from './types/Region';
|
|
19
|
+
import { useI18nStore } from './stores/i18n';
|
|
20
20
|
|
|
21
21
|
export interface Options {
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
23
|
-
i18n?: I18n<typeof messages, {}, {}, string, true>;
|
|
24
23
|
http?: AxiosInstance;
|
|
25
24
|
upload_url?: string;
|
|
26
25
|
locales?: Locales;
|
|
@@ -31,11 +30,6 @@ export interface Options {
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
const config = {
|
|
34
|
-
i18n: createI18n({
|
|
35
|
-
locale: 'en',
|
|
36
|
-
fallbackLocale: 'en',
|
|
37
|
-
messages: { en, fr },
|
|
38
|
-
}),
|
|
39
33
|
http: axios.create(),
|
|
40
34
|
locales: {
|
|
41
35
|
en: 'English',
|
|
@@ -61,10 +55,6 @@ function install(app: App, options?: Options) {
|
|
|
61
55
|
app.component(key, components[key]);
|
|
62
56
|
}
|
|
63
57
|
|
|
64
|
-
if (options?.i18n) {
|
|
65
|
-
config.i18n = options.i18n;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
58
|
if (options?.http) {
|
|
69
59
|
config.http = options.http;
|
|
70
60
|
}
|
|
@@ -92,6 +82,16 @@ function install(app: App, options?: Options) {
|
|
|
92
82
|
if (options?.regions) {
|
|
93
83
|
config.regions = options.regions;
|
|
94
84
|
}
|
|
85
|
+
|
|
86
|
+
if (app.config.globalProperties.$i18n) {
|
|
87
|
+
watch(
|
|
88
|
+
() => app.config.globalProperties.$i18n.locale,
|
|
89
|
+
(locale) => {
|
|
90
|
+
useI18nStore().set(locale);
|
|
91
|
+
},
|
|
92
|
+
{ immediate: true }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export default { install };
|
package/src/stores/dialogs.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineStore } from 'pinia';
|
|
2
|
-
import { config } from '@/index';
|
|
3
2
|
import { Dialog, DialogOptions } from '../types';
|
|
3
|
+
import { t } from '@/i18n';
|
|
4
4
|
|
|
5
5
|
export const useDialogsStore = defineStore('dialogs', {
|
|
6
6
|
state: () => {
|
|
@@ -17,8 +17,8 @@ export const useDialogsStore = defineStore('dialogs', {
|
|
|
17
17
|
color: options.color ?? 'info',
|
|
18
18
|
title: options.title,
|
|
19
19
|
message: options.message,
|
|
20
|
-
confirmText: options.confirmText ??
|
|
21
|
-
cancelText: options.cancelText ??
|
|
20
|
+
confirmText: options.confirmText ?? t('sui.confirm'),
|
|
21
|
+
cancelText: options.cancelText ?? t('sui.cancel'),
|
|
22
22
|
closeOnOutsideClick: options.closeOnOutsideClick ?? true,
|
|
23
23
|
onConfirm:
|
|
24
24
|
options.onConfirm ??
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t } from '@/i18n';
|
|
2
2
|
|
|
3
3
|
export default function (size: number): string {
|
|
4
4
|
const i = Math.floor(Math.log(size) / Math.log(1024));
|
|
5
5
|
|
|
6
6
|
const units = [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
t('sui.units.b'),
|
|
8
|
+
t('sui.units.kb'),
|
|
9
|
+
t('sui.units.mb'),
|
|
10
|
+
t('sui.units.gb'),
|
|
11
|
+
t('sui.units.tb'),
|
|
12
12
|
];
|
|
13
13
|
|
|
14
14
|
return +(size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + units[i];
|
package/src/utils/toHumanList.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t } from '@/i18n';
|
|
2
2
|
|
|
3
3
|
export default function (list: string[], conjunction?: string): string {
|
|
4
4
|
let sentence = '';
|
|
5
5
|
|
|
6
|
-
conjunction = conjunction ? conjunction :
|
|
6
|
+
conjunction = conjunction ? conjunction : t('sui.and');
|
|
7
7
|
|
|
8
8
|
for (let i = 0; i < list.length; i++) {
|
|
9
9
|
const item = list[i];
|