Skip to content

Commit

Permalink
fix: compatible with i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Jan 30, 2023
1 parent 6f7479b commit 89c4a90
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions ui/element/src/mixins/direction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {localeConsumer} from '@alwatr/i18n';
import {localeContextConsumer} from '@alwatr/i18n';

import type {LoggerMixinInterface} from './logging.js';
import type {Constructor} from '@alwatr/type';
Expand All @@ -19,15 +19,15 @@ export function DirectionMixin<T extends Constructor<LoggerMixinInterface>>(

override connectedCallback(): void {
super.connectedCallback();
this._signalListenerList.push(localeConsumer.subscribe(this._localeChanged.bind(this)));
this._signalListenerList.push(localeContextConsumer.subscribe(this._localeChanged.bind(this)));
}

/**
* Update direction from this._dirParent or l10n.locale
*/
protected _updateDir(): void {
this._logger.logMethod('_updateDir');
const dir = this._dirParent?.dir || localeConsumer.getValue()?.direction || document.documentElement.dir;
const dir = this._dirParent?.dir || localeContextConsumer.getValue()?.direction || document.documentElement.dir;
this.setAttribute('dir', dir === 'rtl' ? dir : 'ltr');
}

Expand Down
6 changes: 3 additions & 3 deletions ui/element/src/mixins/localize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {l10nResourceConsumer} from '@alwatr/i18n';
import {l18eContextConsumer} from '@alwatr/i18n';

import type {LoggerMixinInterface} from './logging.js';
import type {ListenerSpec} from '@alwatr/signal';
Expand All @@ -16,14 +16,14 @@ export function LocalizeMixin<T extends Constructor<LoggerMixinInterface>>(

override connectedCallback(): void {
super.connectedCallback();
this.__l10nResourceListener = l10nResourceConsumer.subscribe(() => {
this.__l10nResourceListener = l18eContextConsumer.subscribe(() => {
this._l10nResourceChanged();
});
}

override disconnectedCallback(): void {
if (this.__l10nResourceListener != null) {
l10nResourceConsumer.unsubscribe(this.__l10nResourceListener);
l18eContextConsumer.unsubscribe(this.__l10nResourceListener);
}
super.disconnectedCallback();
}
Expand Down
4 changes: 2 additions & 2 deletions ui/element/src/pwa-element.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {localeConsumer, setLocale} from '@alwatr/i18n';
import {localeContextConsumer, setLocale} from '@alwatr/i18n';
import {routerOutlet, type RoutesConfig} from '@alwatr/router';
import {html, css, type CSSResultGroup, type PropertyValues} from 'lit';
import {cache} from 'lit/directives/cache.js';
Expand Down Expand Up @@ -43,7 +43,7 @@ export class AlwatrPwaElement extends AlwatrSmartElement {
constructor() {
super();
this._initLocale();
localeConsumer.subscribe(this._routeChanged.bind(this));
localeContextConsumer.subscribe(this._routeChanged.bind(this));
}

protected _initLocale(): void {
Expand Down
4 changes: 2 additions & 2 deletions ui/ui-kit/src/chat/chat-footer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {AlwatrDummyElement, css, customElement, html} from '@alwatr/element';
import './chat-text-input.js';
import '../button/icon-button.js';
import {setLocale, localeConsumer} from '@alwatr/i18n';
import {setLocale, localeContextConsumer} from '@alwatr/i18n';

declare global {
interface HTMLElementTagNameMap {
Expand Down Expand Up @@ -40,6 +40,6 @@ export class AlwatrChatFooter extends AlwatrDummyElement {
}

protected _changeLocale(): void {
setLocale(localeConsumer.getValue()?.language !== 'fa' ? 'fa' : 'en');
setLocale(localeContextConsumer.getValue()?.language !== 'fa' ? 'fa' : 'en');
}
}
4 changes: 2 additions & 2 deletions uniquely/flight-finder-pwa/src/component/job-add-form.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {AlwatrSmartElement, customElement, css, html} from '@alwatr/element';
import {message, localeConsumer, number} from '@alwatr/i18n';
import {message, localeContextConsumer, number} from '@alwatr/i18n';
import {eventTrigger} from '@alwatr/signal';

import {cityList} from '../city-list.js';
Expand Down Expand Up @@ -180,7 +180,7 @@ export class JobAddForm extends AlwatrSmartElement {
event,
});

const currentYear = new Date().toLocaleDateString(localeConsumer.getValue()?.code, {
const currentYear = new Date().toLocaleDateString(localeContextConsumer.getValue()?.code, {
numberingSystem: 'latn',
year: 'numeric',
});
Expand Down

0 comments on commit 89c4a90

Please sign in to comment.