Skip to content

Commit

Permalink
feat(keep-pwa): change language
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Jun 14, 2023
1 parent e37cd99 commit d55ec91
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions uniquely/keep-pwa/src/manager/change-language.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {localeContextConsumer, setLocale, l18eContextConsumer} from '@alwatr/i18n';
import {snackbarSignalTrigger} from '@alwatr/ui-kit/snackbar/show-snackbar.js';

import {languageButtonClickEventListener} from './context.js';
import {logger} from './logger.js';

languageButtonClickEventListener.subscribe(() => {
logger.logMethod?.('changeLanguage');
localeContextConsumer.getValue()?.language === 'en'
? setLocale({
code: 'fa-IR',
language: 'fa',
direction: 'rtl',
})
: setLocale({
code: 'en-US',
language: 'en',
direction: 'ltr',
});
});

let rapidClickCount = 0;
let lastClick = 0;
l18eContextConsumer.subscribe(() => {
const now = Date.now();
if (now - lastClick < 1_000) {
rapidClickCount++;
}
lastClick = now;

if (rapidClickCount > 5 && localeContextConsumer.getValue()?.language === 'fa') {
rapidClickCount = 0;

snackbarSignalTrigger.request({
message: 'داداش چی از جون ما می‌خوای؟!\nولی جون ما با سرعت برنامه حال می‌کنی؟!',
duration: -1,
actionLabel: 'ایول',
});
}
});
1 change: 1 addition & 0 deletions uniquely/keep-pwa/src/manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import './change-language.js';
import './context-provider/home-page-content.js';
import './context-provider/l18e.js';

0 comments on commit d55ec91

Please sign in to comment.