mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-05-01 06:37:59 +00:00
feat: initial Pezkuwi Apps rebrand from polkadot-apps
Rebranded terminology: - Polkadot → Pezkuwi - Kusama → Dicle - Westend → Zagros - Rococo → PezkuwiChain - Substrate → Bizinikiwi - parachain → teyrchain Custom logos with Kurdistan brand colors (#e6007a → #86e62a): - bizinikiwi-hexagon.svg - sora-bizinikiwi.svg - hezscanner.svg - heztreasury.svg - pezkuwiscan.svg - pezkuwistats.svg - pezkuwiassembly.svg - pezkuwiholic.svg
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// Copyright 2017-2025 @pezkuwi/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import languageCache from './cache.js';
|
||||
|
||||
type Callback = (error: string | null, data: any) => void;
|
||||
|
||||
type LoadResult = [string | null, Record<string, string> | boolean];
|
||||
|
||||
const loaders: Record<string, Promise<LoadResult>> = {};
|
||||
|
||||
export default class Backend {
|
||||
type = 'backend' as const;
|
||||
|
||||
static type = 'backend' as const;
|
||||
|
||||
async read (lng: string, _namespace: string, responder: Callback): Promise<void> {
|
||||
if (languageCache[lng]) {
|
||||
return responder(null, languageCache[lng]);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
if (!loaders[lng]) {
|
||||
loaders[lng] = this.createLoader(lng);
|
||||
}
|
||||
|
||||
const [error, data] = await loaders[lng];
|
||||
|
||||
return responder(error, data);
|
||||
}
|
||||
|
||||
async createLoader (lng: string): Promise<LoadResult> {
|
||||
try {
|
||||
const response = await fetch(`locales/${lng}/translation.json`, {});
|
||||
|
||||
if (!response.ok) {
|
||||
return [`i18n: failed loading ${lng}`, response.status >= 500 && response.status < 600];
|
||||
} else {
|
||||
languageCache[lng] = await response.json() as Record<string, string>;
|
||||
|
||||
return [null, languageCache[lng]];
|
||||
}
|
||||
} catch (error) {
|
||||
return [(error as Error).message, false];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2025 @pezkuwi/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const languageCache: Record<string, Record<string, string>> = {};
|
||||
|
||||
export default languageCache;
|
||||
@@ -0,0 +1,107 @@
|
||||
// Copyright 2017-2025 @pezkuwi/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { LanguageDetectorModule, Newable } from 'i18next';
|
||||
|
||||
import i18next from 'i18next';
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
|
||||
import { LANGUAGE_DEFAULT, settings } from '@pezkuwi/ui-settings';
|
||||
|
||||
import Backend from './Backend.js';
|
||||
|
||||
// This is a workaround for the above package -
|
||||
//
|
||||
// 1. It does have an ESM export which would be used
|
||||
// 2. The package type is set to commonjs
|
||||
// 3. Unless we run fixup on it, it seems problematic... (here we opt for no fixup)
|
||||
const languageDetector = new (LanguageDetector as unknown as Newable<LanguageDetectorModule & { addDetector: (...args: unknown[]) => unknown }>)();
|
||||
|
||||
languageDetector.addDetector({
|
||||
lookup: () => {
|
||||
const i18nLang = settings.i18nLang;
|
||||
|
||||
return i18nLang === LANGUAGE_DEFAULT
|
||||
? undefined
|
||||
: i18nLang;
|
||||
},
|
||||
name: 'i18nLangDetector'
|
||||
});
|
||||
|
||||
i18next
|
||||
.use(languageDetector)
|
||||
.use(initReactI18next)
|
||||
.use(Backend)
|
||||
.init({
|
||||
backend: {},
|
||||
debug: false,
|
||||
detection: {
|
||||
order: ['i18nLangDetector', 'navigator']
|
||||
},
|
||||
fallbackLng: false,
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
prefix: '{{',
|
||||
suffix: '}}'
|
||||
},
|
||||
keySeparator: false,
|
||||
load: 'languageOnly',
|
||||
ns: [
|
||||
'apps',
|
||||
'apps-config',
|
||||
'apps-electron',
|
||||
'apps-routing',
|
||||
'app-accounts',
|
||||
'app-claims',
|
||||
'app-contracts',
|
||||
'app-council',
|
||||
'app-democracy',
|
||||
'app-explorer',
|
||||
'app-extrinsics',
|
||||
'app-generic-asset',
|
||||
'app-js',
|
||||
'app-teyrchains',
|
||||
'app-poll',
|
||||
'app-rpc',
|
||||
'app-settings',
|
||||
'app-signing',
|
||||
'app-society',
|
||||
'app-staking',
|
||||
'app-staking-async',
|
||||
'app-staking-legacy',
|
||||
'app-storage',
|
||||
'app-sudo',
|
||||
'app-tech-comm',
|
||||
'app-treasury',
|
||||
'react-api',
|
||||
'react-components',
|
||||
'react-hooks',
|
||||
'react-params',
|
||||
'react-query',
|
||||
'react-signer',
|
||||
'translation'
|
||||
],
|
||||
nsSeparator: false,
|
||||
react: {
|
||||
useSuspense: true
|
||||
},
|
||||
returnEmptyString: false,
|
||||
returnNull: false
|
||||
})
|
||||
.catch((error: Error): void =>
|
||||
console.log('i18n: failure', error)
|
||||
);
|
||||
|
||||
settings.on('change', (settings): void => {
|
||||
(
|
||||
settings.i18nLang === LANGUAGE_DEFAULT
|
||||
// If we want to use the default language, we need to pass no
|
||||
// actual param through here
|
||||
// https://github.com/i18next/i18next/blob/21eac5a605601ec1067aac3583c6ec6bc2ecd3b7/src/i18next.js#L366
|
||||
? i18next.changeLanguage()
|
||||
: i18next.changeLanguage(settings.i18nLang)
|
||||
).catch(console.error);
|
||||
});
|
||||
|
||||
export default i18next;
|
||||
Reference in New Issue
Block a user