Migrate to lingui
Switch to "lingui" for better DX. Tried to persist existing languages as much as possible. Removed "vite-plugin-node-polyfills" because it's incompatible with "lingui"
This commit is contained in:
@@ -6,10 +6,10 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { MessageDescriptor } from '@lingui/core';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { TapZoneLayouts, TapZoneRegion, TapZoneRegionType } from '@/features/reader/tap-zones/TapZoneLayout.types.ts';
|
||||
|
||||
import { TranslationKey } from '@/base/Base.types.ts';
|
||||
|
||||
export const READER_TAP_ZONE_LAYOUTS: Record<TapZoneLayouts, TapZoneRegion[]> = {
|
||||
/**
|
||||
* +---+---+---+
|
||||
@@ -136,17 +136,17 @@ export const READER_TAP_ZONE_LAYOUTS: Record<TapZoneLayouts, TapZoneRegion[]> =
|
||||
],
|
||||
};
|
||||
|
||||
export const TAP_ZONE_REGION_TYPE_DATA: Record<TapZoneRegionType, { text: TranslationKey; color: string }> = {
|
||||
export const TAP_ZONE_REGION_TYPE_DATA: Record<TapZoneRegionType, { text: MessageDescriptor; color: string }> = {
|
||||
[TapZoneRegionType.PREVIOUS]: {
|
||||
text: 'global.label.previous',
|
||||
text: msg`Previous`,
|
||||
color: 'rgba(255, 114, 118, .5)',
|
||||
},
|
||||
[TapZoneRegionType.NEXT]: {
|
||||
text: 'global.label.next',
|
||||
text: msg`Next`,
|
||||
color: 'rgba(144, 238, 144, .5)',
|
||||
},
|
||||
[TapZoneRegionType.MENU]: {
|
||||
text: 'global.label.menu',
|
||||
text: msg`Menu`,
|
||||
color: 'rgba(0, 0, 0, .5)',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import i18next, { t as translate } from 'i18next';
|
||||
import { CSSProperties } from 'react';
|
||||
import {
|
||||
ReaderTapZoneRect,
|
||||
@@ -20,6 +19,8 @@ import {
|
||||
TAP_ZONE_REGION_TYPE_DATA,
|
||||
} from '@/features/reader/tap-zones/ReaderTapZone.constants.ts';
|
||||
|
||||
import { i18n } from '@/i18n';
|
||||
|
||||
interface InvertMode extends TapZoneInvertMode {
|
||||
isRTL: boolean;
|
||||
}
|
||||
@@ -78,7 +79,7 @@ export class ReaderTapZoneService {
|
||||
const isSameWidth = this.width === canvasWidth;
|
||||
const isSameHeight = this.height === canvasHeight;
|
||||
const doesCanvasExist = !!this.canvas;
|
||||
const isSameLanguage = this.language === i18next.language;
|
||||
const isSameLanguage = this.language === i18n.locale;
|
||||
const isSameInvertMode =
|
||||
this.invertMode?.vertical === invertMode.vertical &&
|
||||
this.invertMode.horizontal === invertMode.horizontal &&
|
||||
@@ -104,8 +105,8 @@ export class ReaderTapZoneService {
|
||||
regions: TapZoneRegion[],
|
||||
): void {
|
||||
regions.forEach(({ type, rect: [rectX, rectY, rectWidth, rectHeight] }) => {
|
||||
const { text: translationKey, color } = TAP_ZONE_REGION_TYPE_DATA[type];
|
||||
const text = translate(translationKey);
|
||||
const { text: translation, color } = TAP_ZONE_REGION_TYPE_DATA[type];
|
||||
const text = i18n._(translation);
|
||||
|
||||
const calcActualValue = (value: number, size: number) => (value / 100) * size;
|
||||
const x = calcActualValue(rectX, canvasWidth);
|
||||
@@ -168,7 +169,7 @@ export class ReaderTapZoneService {
|
||||
this.canvas = canvas;
|
||||
this.width = canvasWidth;
|
||||
this.height = canvasHeight;
|
||||
this.language = i18next.language;
|
||||
this.language = i18n.locale;
|
||||
this.invertMode = invertMode;
|
||||
this.regions = regions;
|
||||
this.fontStyle = fontStyle;
|
||||
|
||||
Reference in New Issue
Block a user