Skip to content

Commit

Permalink
update ui kit next
Browse files Browse the repository at this point in the history
  • Loading branch information
Thykof committed May 17, 2024
1 parent 9dc70b0 commit 02d0525
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 1,319 deletions.
1,355 changes: 159 additions & 1,196 deletions web/massastation/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions web/massastation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"prepare": "cd ../.. && husky install web/massastation/.husky"
},
"dependencies": {
"@massalabs/massa-web3": "^1.16.1",
"@massalabs/react-ui-kit": "^0.0.4-dev",
"@massalabs/massa-web3": "^4.0.2-dev",
"@massalabs/react-ui-kit": "^0.0.5-dev",
"@tanstack/react-query": "^4.29.5",
"axios": "^1.4.0",
"dot-object": "^2.1.4",
Expand Down
1 change: 0 additions & 1 deletion web/massastation/src/const/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './const';
export * from './env/env';
export * from './intl/intl';
export * from './pages/pages';
export * from './url/url';
4 changes: 0 additions & 4 deletions web/massastation/src/const/intl/intl.ts

This file was deleted.

39 changes: 0 additions & 39 deletions web/massastation/src/custom/useLocalStorage.ts

This file was deleted.

1 change: 0 additions & 1 deletion web/massastation/src/i18n/fr_FR.json

This file was deleted.

77 changes: 2 additions & 75 deletions web/massastation/src/i18n/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,7 @@
// STYLES

// EXTERNALS
import dot from 'dot-object';

// LOCALS
import I18n from '@massalabs/react-ui-kit/src/lib/i18n/i18n';
import enUs from './en_US.json';
import frFR from './fr_FR.json';
import { INTL } from '../const/intl/intl';

type Copy = Record<string, string | object>;

class I18n {
private lang: string;
private copy: Copy;

constructor() {
this.lang = this._getLang();
this.copy = this._getCopy();
}

public t(key: string, interpolations?: Record<string, string>): string {
let copy = this.copy;
// we are using pick in order to make life easier when the day for plurals and copy with params arrives
const result = dot.pick(key, copy);

if (!result) {
console.warn(`I18n::t:: No translation found for key ${key}`);
}

return interpolations
? this._interpolateKeys(result, interpolations)
: result ?? key;
}

private _getLang(): string {
let urlParams = new URLSearchParams(window.location.search);
let fromUrl = urlParams.get('l');

if (fromUrl) {
localStorage.setItem('massa-station-lang', fromUrl);
}

return fromUrl || localStorage.getItem('massa-station-lang') || INTL.EN_us;
}

private _getCopy(): Copy {
let lang = this.lang;

if (lang === INTL.EN_us) {
return enUs;
} else if (lang === INTL.FR_fr) {
return frFR;
} else {
console.warn(
`I18n::_getCopy:: We may not support yet ${lang}. Loading 'en_US' then... `,
);
return enUs;
}
}

private _interpolateKeys(
str: string,
replacements: Record<string, string>,
char1 = '{',
char2 = '}',
): string {
const regex = new RegExp(`${char1}[^${char2}]*${char2}`, 'g');

return str.replace(regex, (match) => {
const key = match.slice(1, -1);
return replacements[key] ?? match;
});
}
}

const Intl = new I18n();
const Intl = new I18n({ EN_us: enUs });
Object.freeze(Intl);

export default Intl;
2 changes: 1 addition & 1 deletion web/massastation/src/pages/Base/Base.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect, useState } from 'react';
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
import { useLocalStorage } from '@/custom/useLocalStorage';
import { useConfigStore } from '@/store/store';

import { Navigator, Theme, Toast } from '@massalabs/react-ui-kit';
import { useLocalStorage } from '@massalabs/react-ui-kit/src/lib/util/hooks/useLocalStorage';
import { FiCodepen, FiGlobe, FiHome, FiSun, FiMoon } from 'react-icons/fi';
import { LayoutStation } from '@/layouts/LayoutStation/LayoutStation';

Expand Down

0 comments on commit 02d0525

Please sign in to comment.