-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update ui kit next * clean deps
- Loading branch information
Showing
10 changed files
with
279 additions
and
1,441 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters