Skip to content

Commit

Permalink
feat(i18n): setup i18next extension
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoirelacoste authored and lutangar committed Mar 12, 2021
1 parent 04325ef commit f2e3ebb
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
23 changes: 23 additions & 0 deletions src/app/content/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import i18n from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';
import resources from '../locales/resources';

const options = {
resources,
fallbackLng: 'fr_FR',
ns: ['extension'],
defaultNS: 'extension',
debug: true,
interpolation: {
escapeValue: false // react already safes from xss
},
keySeparator: '.'
};

i18n
.use(initReactI18next)
.use(LanguageDetector)
.init(options);

export default i18n;
1 change: 1 addition & 0 deletions src/app/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (window.location.href.match((process.env as AppEnv).PROFILES_ORIGIN)) {

import { Scope } from '@sentry/browser';
import { AppEnv, CustomWindow } from 'types';
import './i18n';

if (!(window as CustomWindow).__BULLES__CONTENT_SCRIPT_INJECTED__) {
Logger.info('Running content script ...');
Expand Down
1 change: 1 addition & 0 deletions src/app/locales/extension/en_GB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
6 changes: 6 additions & 0 deletions src/app/locales/extension/fr_FR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Contributions": "Contributions",
"Abonnements": "Test",
"Aide": "Aide",
"Mon compte": "Mon compte"
}
15 changes: 15 additions & 0 deletions src/app/locales/resources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import extensionFR from './extension/fr_FR.json';
import extensionEN from './extension/en_GB.json';

const resources = {
// eslint-disable-next-line @typescript-eslint/camelcase
fr_FR: {
extension: extensionFR
},
// eslint-disable-next-line @typescript-eslint/camelcase
en_GB: {
extension: extensionEN
}
};

export default resources;
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ import {
FooterRoute,
footerRoutes
} from '../../../../app/content/footerRoutes';
import { useTranslation } from 'react-i18next';

interface NotificationFooterProps {
children?: FooterRoute[];
}

const NotificationFooter = ({ children }: NotificationFooterProps) => (
<FooterContainer>
{children &&
children.map(route => (
<NavLink key={route.location as string} to={route.location}>
{route.element}
</NavLink>
))}
</FooterContainer>
);
const NotificationFooter = ({ children }: NotificationFooterProps) => {
const { t } = useTranslation();
return (
<FooterContainer>
{children &&
children.map(route => (
<NavLink key={route.location as string} to={route.location}>
{t(route.element)}
</NavLink>
))}
</FooterContainer>
);
};

NotificationFooter.defaultProps = {
children: footerRoutes
Expand Down

0 comments on commit f2e3ebb

Please sign in to comment.