Skip to content

Commit

Permalink
Drop vue-i18n as dependence (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
ViZhe authored Jul 1, 2021
1 parent a4b353f commit 9646a0c
Show file tree
Hide file tree
Showing 31 changed files with 552 additions and 574 deletions.
2 changes: 1 addition & 1 deletion .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import messages from './locales';
app.use(Qui, {
localization: {
locale: 'en',
customI18nMessages: messages
messages
}
});

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default {
Configure setup:

- import styles separately to avoid unused css
- set customI18nMessages to support any language for components
- set `localization.messages` to support any language for components
- change zIndex of appeared components (e.g Dialogs, Notifications, Dropdowns etc.)
- control setup of components

Expand All @@ -107,7 +107,7 @@ const Qui = createQui({
localization: {
// Russian language by default, you can set `en` for English
locale: 'en',
customI18nMessages: {
messages: {
// rewrite default texts, see the source: src/qComponents/constants/locales
en: {
QDatepicker: {
Expand All @@ -132,7 +132,7 @@ Please refer to each component's [Stories](https://qvant-lab.github.io/qui-max/)

- Russian ✅
- English ✅
- Also you can use any language by setting texts for components via 'customI18nMessages' property in the Qui instance. See the example above.
- Also you can use any language by setting texts for components via `localization.messages` property in the Qui instance. See the example above.

## Browser Support

Expand Down
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"colord": "^2.0.1",
"date-fns": "^2.22.1",
"focus-visible": "^5.2.0",
"lodash-es": "^4.17.21",
"vue-i18n": "^9.0.0"
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"vue": "^3.1.2"
Expand All @@ -36,20 +35,20 @@
"@babel/core": "^7.14.6",
"@qvant/prettier-config": "^0.0.1",
"@qvant/stylelint-config": "^0.0.1",
"@storybook/addon-actions": "^6.3.0",
"@storybook/addon-essentials": "^6.3.0",
"@storybook/addon-links": "^6.3.0",
"@storybook/addon-storysource": "^6.3.0",
"@storybook/builder-webpack5": "^6.3.0",
"@storybook/manager-webpack5": "^6.3.0",
"@storybook/addon-actions": "^6.3.1",
"@storybook/addon-essentials": "^6.3.1",
"@storybook/addon-links": "^6.3.1",
"@storybook/addon-storysource": "^6.3.1",
"@storybook/builder-webpack5": "^6.3.1",
"@storybook/manager-webpack5": "^6.3.1",
"@storybook/preset-scss": "^1.0.3",
"@storybook/storybook-deployer": "^2.8.10",
"@storybook/vue3": "^6.3.0",
"@storybook/vue3": "^6.3.1",
"@types/lodash-es": "^4.17.4",
"@types/node": "^15.12.5",
"@types/sass": "^1.16.0",
"@typescript-eslint/eslint-plugin": "^4.27.0",
"@typescript-eslint/parser": "^4.27.0",
"@typescript-eslint/eslint-plugin": "^4.28.1",
"@typescript-eslint/parser": "^4.28.1",
"@vitejs/plugin-vue": "^1.2.4",
"@vue/compiler-sfc": "^3.1.2",
"@vue/eslint-config-typescript": "^7.0.0",
Expand Down Expand Up @@ -78,7 +77,7 @@
"vite": "^2.3.8",
"vite-plugin-dts": "^0.5.1",
"vue": "^3.1.2",
"vue-loader": "^16.2.0"
"vue-loader": "^16.3.0"
},
"files": ["dist"],
"main": "./dist/qui-max.umd.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<script lang="ts">
import { defineComponent, inject, computed } from 'vue';
import { isNumber, isEmpty } from 'lodash-es';
import { useI18n } from 'vue-i18n';
import { t } from '@/qComponents/locale';
import QInput from '@/qComponents/QInput';
import type { Nullable } from '#/helpers';
Expand Down Expand Up @@ -73,8 +73,6 @@ export default defineComponent({
!isEmpty(qCascader.modelValue.value)
);
const { t } = useI18n();
const placeholder = computed<Nullable<string>>(() => {
const text = qCascader.placeholder.value ?? t('QCascader.placeholder');
if (!qCascader.multiple.value) return text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ import {
nextTick,
inject
} from 'vue';
import { useI18n } from 'vue-i18n';
import { colord } from 'colord';
import type { Colord } from 'colord';
import { t } from '@/qComponents/locale';
import { validateArray } from '@/qComponents/helpers';
import { CLEAR_EVENT, CLOSE_EVENT } from '@/qComponents/constants/events';
import QButton from '@/qComponents/QButton';
Expand Down Expand Up @@ -245,8 +245,6 @@ export default defineComponent({
{ immediate: true }
);
const { t } = useI18n();
return {
t,
dropdown,
Expand Down
3 changes: 1 addition & 2 deletions src/qComponents/QColorPicker/src/QPickerDropdown/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Ref, ComputedRef } from 'vue';
import type { Composer } from 'vue-i18n';

import type { Nullable } from '#/helpers';

Expand All @@ -16,7 +15,7 @@ export interface QPickerDropdownProps {
}

export interface QPickerDropdownInstance {
t: Composer['t'];
t: (key: string) => string;
dropdown: Ref<Nullable<HTMLElement>>;
saturation: Ref<number>;
value: Ref<number>;
Expand Down
4 changes: 1 addition & 3 deletions src/qComponents/QDatePicker/src/QDatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ import {
startOfYear,
parseISO
} from 'date-fns';
import { useI18n } from 'vue-i18n';
import { getConfig } from '@/qComponents/config';
import { t } from '@/qComponents/locale';
import { notNull, validateArray } from '@/qComponents/helpers';
import QInput from '@/qComponents/QInput';
import type { QFormProvider } from '@/qComponents/QForm';
Expand Down Expand Up @@ -654,8 +654,6 @@ export default defineComponent({
}
);
const { t } = useI18n();
onBeforeUnmount(() => destroyPopper());
provide<QDatePickerProvider>('qDatePicker', {
Expand Down
4 changes: 1 addition & 3 deletions src/qComponents/QDatePicker/src/panel/Date/DatePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ import {
import type { PropType } from 'vue';
import { subMonths, addMonths, subYears, addYears } from 'date-fns';
import { isNil } from 'lodash-es';
import { useI18n } from 'vue-i18n';
import { t } from '@/qComponents/locale';
import { getConfig } from '@/qComponents/config';
import type { Nullable } from '#/helpers';
Expand Down Expand Up @@ -333,8 +333,6 @@ export default defineComponent({
ctx.emit('pick', value);
};
const { t } = useI18n();
const moveWithinPeriod = (e: KeyboardEvent): void => {
if (!state?.periodCells?.length || !state.panelInFocus) return;
const nextNodeIndex = getPeriodNextNodeIndex(
Expand Down
3 changes: 1 addition & 2 deletions src/qComponents/QDatePicker/src/panel/Date/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ComputedRef, Ref } from 'vue';
import type { TranslateResult, Path, Locale } from 'vue-i18n';

import type { Nullable } from '#/helpers';

Expand Down Expand Up @@ -43,7 +42,7 @@ interface DatePanelInstance {
handleShortcutClick: (shortcut: Date) => void;
handlePeriodPick: (month: number, year: number, type: string) => void;
handleDatePick: (value: DatePanelPropModelValue) => void;
t: (key: Path, locale?: Locale) => TranslateResult;
t: (key: string) => string;
}

export {
Expand Down
4 changes: 1 addition & 3 deletions src/qComponents/QDatePicker/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Instance } from '@popperjs/core';
import type { ComputedRef, Ref } from 'vue';
import type { Composer } from 'vue-i18n';

import type { QInputInstance } from '@/qComponents/QInput';
import type { Nullable, UnwrappedInstance } from '#/helpers';
Expand Down Expand Up @@ -90,7 +89,6 @@ interface QDatePickerInstance {
root: Ref<Nullable<HTMLElement>>;
panel: Ref<UnwrappedInstance<DatePanelInstance>>;
reference: Ref<Nullable<UnwrappedInstance<QInputInstance> | HTMLElement>>;

isRanged: ComputedRef<boolean>;
isPickerDisabled: ComputedRef<boolean>;
isValueEmpty: ComputedRef<boolean>;
Expand Down Expand Up @@ -121,7 +119,7 @@ interface QDatePickerInstance {
handleRangeClick: () => void;
handleClose: () => void;
handleIconClick: (event: MouseEvent) => void;
t: Composer['t'];
t: (key: string) => string;
}

export {
Expand Down
5 changes: 2 additions & 3 deletions src/qComponents/QInput/src/QInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

<script lang="ts">
import { inject, computed, ref, reactive, watch, defineComponent } from 'vue';
import { useI18n } from 'vue-i18n';
import {
UPDATE_MODEL_VALUE_EVENT,
CHANGE_EVENT,
Expand All @@ -68,6 +68,7 @@ import {
CLEAR_EVENT,
INPUT_EVENT
} from '@/qComponents/constants/events';
import { t } from '@/qComponents/locale';
import type { QFormProvider } from '@/qComponents/QForm';
import type { QFormItemProvider } from '@/qComponents/QFormItem';
import type { Nullable } from '#/helpers';
Expand Down Expand Up @@ -269,8 +270,6 @@ export default defineComponent({
}
);
const { t } = useI18n();
return {
root,
state,
Expand Down
3 changes: 1 addition & 2 deletions src/qComponents/QInput/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Ref, ComputedRef } from 'vue';
import type { Composer } from 'vue-i18n';

import type { Nullable } from '#/helpers';

Expand Down Expand Up @@ -44,5 +43,5 @@ export interface QInputInstance {
handleInput: (event: Event) => void;
handleChange: (event: Event) => void;
updateModel: (event: Event) => void;
t: Composer['t'];
t: (key: string) => string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ export default defineComponent({
const zIndex = getConfig('nextZIndex');
const preparedContent = computed<QMessageBoxComponent>(() => {
if (isExternalComponent(props.content)) return props.content;
if (isExternalComponent(props.content)) {
return {
props: {},
listeners: {},
...props.content
};
}
if (isInternalComponent(props.content)) {
return {
Expand Down
3 changes: 0 additions & 3 deletions src/qComponents/QMessageBox/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createApp, nextTick } from 'vue';
import type { App } from 'vue';

import { installI18n } from '@/qComponents/constants/locales';
import type { Optional, UnwrappedInstance } from '#/helpers';

import { QMessageBoxContainer } from './QMessageBoxContainer';
Expand Down Expand Up @@ -49,8 +48,6 @@ export const createMessageBox = (

options?.onBeforeMount?.(app);

installI18n(app);

const container = app.mount(document.createElement('div'));
options?.onMounted?.(
app,
Expand Down
3 changes: 0 additions & 3 deletions src/qComponents/QNotification/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createApp, ref, nextTick } from 'vue';

import { installI18n } from '@/qComponents/constants/locales';
import { randId } from '@/qComponents/helpers';

import QNotificationContainer from './QNotificationContainer';
Expand Down Expand Up @@ -38,8 +37,6 @@ export const createNotification = (
onRemove: closeNotify
});

installI18n(app);

const component = app.mount(document.createElement('div'));

config?.onMounted?.(component, app);
Expand Down
4 changes: 1 addition & 3 deletions src/qComponents/QSelect/src/QSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ import {
isNumber
} from 'lodash-es';
import { createPopper } from '@popperjs/core';
import { useI18n } from 'vue-i18n';
import { t } from '@/qComponents/locale';
import { useResizeListener } from '@/qComponents/hooks';
import type { QInputInstance } from '@/qComponents/QInput';
import type { QFormProvider } from '@/qComponents/QForm';
Expand Down Expand Up @@ -255,8 +255,6 @@ export default defineComponent({
const qFormItem = inject<Nullable<QFormItemProvider>>('qFormItem', null);
const qForm = inject<Nullable<QFormProvider>>('qForm', null);
const { t } = useI18n();
const state = reactive<QSelectState>({
options: [],
selected: props.multiple ? [] : null,
Expand Down
3 changes: 1 addition & 2 deletions src/qComponents/QSelect/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Ref, ComputedRef } from 'vue';
import type { Instance as PopperInstance } from '@popperjs/core';
import type { Composer } from 'vue-i18n';

import type { QOptionModel, QOptionPropValue } from '@/qComponents/QOption';
import type { QScrollbarInstance } from '@/qComponents/QScrollbar';
Expand Down Expand Up @@ -50,7 +49,7 @@ interface QSelectInstance {
onInputChange: () => void;
deleteTag: (tag: QOptionModel) => void;
afterLeave: () => void;
t: Composer['t'];
t: (key: string) => string;
}

interface QSelectProvider {
Expand Down
4 changes: 1 addition & 3 deletions src/qComponents/QTable/src/QTableEmpty/QTableEmpty.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

<script lang="ts">
import { defineComponent, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { t } from '@/qComponents/locale';
import image from '@/assets/empty-table-v2.svg';
import type { QTableEmptyProps, QTableEmptyInstance } from './types';
Expand All @@ -35,8 +35,6 @@ export default defineComponent({
},
setup(props: QTableEmptyProps): QTableEmptyInstance {
const { t } = useI18n();
const noDataText = computed<string>(
() => props.emptyText || t('QTable.noDataText')
);
Expand Down
3 changes: 1 addition & 2 deletions src/qComponents/QTable/src/QTableEmpty/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ComputedRef } from 'vue';
import type { Composer } from 'vue-i18n';

import type { Nullable } from '#/helpers';

Expand All @@ -8,7 +7,7 @@ export interface QTableEmptyProps {
}

export interface QTableEmptyInstance {
t: Composer['t'];
t: (key: string) => string;
image: string;
noDataText: ComputedRef<string>;
}
4 changes: 1 addition & 3 deletions src/qComponents/QTextarea/src/QTextarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import {
watch,
PropType
} from 'vue';
import { useI18n } from 'vue-i18n';
import { t } from '@/qComponents/locale';
import { validateArray } from '@/qComponents/helpers';
import {
UPDATE_MODEL_VALUE_EVENT,
Expand Down Expand Up @@ -211,8 +211,6 @@ export default defineComponent({
resizeTextarea();
});
const { t } = useI18n();
return {
t,
textareaCalcStyle,
Expand Down
Loading

0 comments on commit 9646a0c

Please sign in to comment.