-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1784 from 3scale/portafly/THREESCALE-4688-localiz…
…ation-framework-react-i18next Portafly: Adding reacti18next
- Loading branch information
Showing
20 changed files
with
290 additions
and
78 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react' | ||
import { Brand } from '@patternfly/react-core' | ||
import { useTranslation } from 'i18n/useTranslation' | ||
import { useHistory } from 'react-router-dom' | ||
import { AppLayout } from 'components' | ||
import logo from 'assets/logo.svg' | ||
|
||
const Root: React.FunctionComponent = ({ children }) => { | ||
const { t } = useTranslation('shared') | ||
const Logo = <Brand src={logo} alt={t('logo_alt_text')} /> | ||
|
||
const navItems = [ | ||
{ | ||
title: t('nav_items.overview'), | ||
to: '/', | ||
exact: true | ||
}, | ||
{ | ||
title: t('nav_items.analytics'), | ||
to: '/analytics', | ||
items: [ | ||
{ to: '/analytics/usage', title: t('nav_items.analytics_usage') } | ||
] | ||
}, | ||
{ | ||
title: t('nav_items.applications'), | ||
to: '/applications', | ||
items: [ | ||
{ to: '/applications', title: t('nav_items.applications_listing') }, | ||
{ to: '/applications/plans', title: t('nav_items.applications_app_plans') } | ||
] | ||
}, | ||
{ | ||
title: t('nav_items.integration'), | ||
to: '/integration', | ||
items: [ | ||
{ to: '/integration/configuration', title: t('nav_items.integration_configuration') } | ||
] | ||
} | ||
] | ||
|
||
const history = useHistory() | ||
const logoProps = React.useMemo( | ||
() => ({ | ||
onClick: () => history.push('/') | ||
}), | ||
[history] | ||
) | ||
return ( | ||
<AppLayout | ||
logo={Logo} | ||
logoProps={logoProps} | ||
navVariant="vertical" | ||
navItems={navItems} | ||
navGroupsStyle="expandable" | ||
> | ||
{children} | ||
</AppLayout> | ||
) | ||
} | ||
|
||
export { Root } |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import i18n, { FormatFunction } from 'i18next' | ||
import LanguageDetector from 'i18next-browser-languagedetector' | ||
import { initReactI18next } from 'react-i18next' | ||
import { ITranslationsPages, Translations, EN } from 'i18n' | ||
|
||
const formatFn: FormatFunction = (value, format) => { | ||
if (format === 'uppercase') return value.toUpperCase() | ||
if (format === 'lowercase') return value.toLowerCase() | ||
return value | ||
} | ||
|
||
const sections: Array<ITranslationsPages> = ['shared', 'overview', 'analytics', 'applications', 'integration'] | ||
|
||
const options = { | ||
lng: EN, | ||
fallbackLng: [EN], | ||
debug: false, | ||
interpolation: { | ||
format: formatFn, | ||
escapeValue: false | ||
}, | ||
ns: sections, | ||
defaultNS: 'shared', | ||
react: { | ||
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i'] | ||
}, | ||
resources: Translations | ||
} | ||
|
||
i18n.use(LanguageDetector) | ||
.use(initReactI18next) | ||
.init(options) | ||
|
||
export { i18n } |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './i18n' | ||
export * from './locales' | ||
export * from './supported-languages' | ||
export * from './useTranslation' |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"page_title": "Analytics | Portafly", | ||
"page_title_desc": "Page title of the Analytics page", | ||
"body_title": "Analytics", | ||
"body_title_desc": "Body title of the Analytics page", | ||
"subtitle": "This is the Analytics page", | ||
"subtitle_desc": "Subtitle of the Analytics page" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"page_title": "Applications | Portafly", | ||
"page_title_desc": "Page title of the Applications page", | ||
"body_title": "Applications", | ||
"body_title_desc": "Body title of the Applications page", | ||
"subtitle": "This is the Applications page", | ||
"subtitle_desc": "Subtitle of the Applications page" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import shared from 'i18n/locales/en/shared.json' | ||
import overview from 'i18n/locales/en/overview.json' | ||
import analytics from 'i18n/locales/en/analytics.json' | ||
import applications from 'i18n/locales/en/applications.json' | ||
import integration from 'i18n/locales/en/integration.json' | ||
|
||
export { | ||
shared, | ||
overview, | ||
analytics, | ||
applications, | ||
integration | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"page_title": "Integration | Portafly", | ||
"page_title_desc": "Page title of the Integration page", | ||
"body_title": "Integration", | ||
"body_title_desc": "Body title of the Integration page", | ||
"subtitle": "This is the Integration page", | ||
"subtitle_desc": "Subtitle of the Integration page" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"page_title": "Overview | Portafly", | ||
"page_title_desc": "Page title of the Overview page", | ||
"body_title": "Overview", | ||
"body_title_desc": "Body title of the Overview page", | ||
"subtitle": "This is the Overview page", | ||
"subtitle_desc": "Subtitle of the Overview page" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"logo_alt_text": "Red Hat Integration logo", | ||
"logo_alt_text_desc": "Alt attribute of the main logo", | ||
"nav_items": { | ||
"overview": "Overview", | ||
"overview_desc": "Title of Overview menu item", | ||
"analytics": "Analytics", | ||
"analytics_desc": "Title of Analytics menu item", | ||
"analytics_usage": "Usage", | ||
"analytics_usage_desc": "Title of Analytics > Usage menu item", | ||
"applications": "Applications", | ||
"applications_desc": "Title of Applications menu item", | ||
"applications_listing": "Listing", | ||
"applications_listing_desc": "Title of Applications > Listing menu item", | ||
"applications_app_plans": "Applications Plans", | ||
"applications_app_plans_desc": "Title of Applications > Applications Plans menu item", | ||
"integration": "Integration", | ||
"integration_desc": "Title of Integration menu item", | ||
"integration_configuration": "Configuration", | ||
"integration_configuration_desc": "Title of Integration > Configuration menu item" | ||
}, | ||
"navigation_items_desc": "Titles of navigation items", | ||
"format": { | ||
"uppercase": "{{text, uppercase}}", | ||
"uppercase_desc": "Formats a text as uppercase", | ||
"lowercase": "{{text, lowercase}}", | ||
"lowercase_desc": "Formats a text as lowercase" | ||
}, | ||
"format_desc": "Utilities to format text" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ISupportedLanguages } from 'i18n' | ||
import * as en from 'i18n/locales/en' | ||
|
||
export type ITranslationsPages = keyof typeof en | ||
export type ITranslations = { [P in ITranslationsPages]: any } | ||
|
||
const Translations: Record<ISupportedLanguages, ITranslations> = { | ||
en | ||
} | ||
|
||
export { Translations } |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const EN = 'en' | ||
|
||
export type ISupportedLanguages = typeof EN // | typeof ... |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useTranslation, UseTranslationOptions } from 'react-i18next' | ||
import { ITranslationsPages } from 'i18n' | ||
|
||
/** | ||
* This wrapper mostly allow us to control what strings we pass | ||
* into useTranslation and provides the IDE with intellisense for | ||
* that matter. | ||
*/ | ||
const useTranslationWrapper = ( | ||
ns?: ITranslationsPages | Array<ITranslationsPages>, | ||
options?: UseTranslationOptions | ||
) => useTranslation(ns, options) | ||
|
||
export { useTranslationWrapper as useTranslation } |
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,6 +1,7 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import '@patternfly/react-core/dist/styles/base.css' | ||
import 'i18n/i18n' | ||
import { App } from 'App' | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')) |
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
Oops, something went wrong.