Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-component): localization support #3604

Merged
merged 42 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1c8010c
Add translation support to react-components
pramodcog Aug 21, 2023
daf8f56
updated package.json with i18n commands for translation
pramodcog Aug 21, 2023
dd0e2f7
updated on demand workflow push
pramodcog Aug 21, 2023
7531c3a
Merge master into pramodcog/UX-1220
cognite-bulldozer[bot] Aug 21, 2023
15cdf66
added react-router-dom dependency
pramodcog Aug 21, 2023
cb48dc2
Merge branch 'pramodcog/UX-1220' of https://github.com/cognitedata/re…
pramodcog Aug 21, 2023
dced329
Merge refs/heads/master into pramodcog/UX-1220
cognite-bulldozer[bot] Aug 21, 2023
45dcfcc
test workflow for current branch
pramodcog Aug 21, 2023
fcb8b0e
Merge branch 'pramodcog/UX-1220' of https://github.com/cognitedata/re…
pramodcog Aug 21, 2023
7f86ab3
test yarn
pramodcog Aug 21, 2023
dea6366
test
pramodcog Aug 21, 2023
35b75ee
npm authentication
pramodcog Aug 21, 2023
f267199
added i18n path to point to react-component
pramodcog Aug 21, 2023
32362a2
added react-component build into workflow for testing
pramodcog Aug 21, 2023
7f1383d
corrected path
pramodcog Aug 21, 2023
caf4dd6
pointed working directory to react-components
pramodcog Aug 21, 2023
80118ed
Merge refs/heads/master into pramodcog/UX-1220
cognite-bulldozer[bot] Aug 21, 2023
02706b4
test
pramodcog Aug 21, 2023
bc1e453
Merge branch 'pramodcog/UX-1220' of https://github.com/cognitedata/re…
pramodcog Aug 21, 2023
7849b45
reverted back np authentication
pramodcog Aug 21, 2023
2181050
added NPM_TOKEN into save transalation
pramodcog Aug 22, 2023
eaf55e3
Merge refs/heads/master into pramodcog/UX-1220
cognite-bulldozer[bot] Aug 22, 2023
eba6b7f
added locize-cli package to fix script run for locize
pramodcog Aug 22, 2023
c80bc5b
Merge branch 'pramodcog/UX-1220' of https://github.com/cognitedata/re…
pramodcog Aug 22, 2023
6909241
updated workflow trigger to on-demand
pramodcog Aug 22, 2023
58e6c5b
updated the translation component linking
pramodcog Aug 23, 2023
c9965b7
Merge branch 'master' into pramodcog/UX-1220
pramodcog Aug 29, 2023
e3575f5
using addNamespace in i18n wrapper to access translation
pramodcog Aug 30, 2023
a845ed9
Merge branch 'master' into pramodcog/UX-1220
pramodcog Sep 1, 2023
2b8282e
work around add as suggested by Christopher for issue in FDX on impor…
pramodcog Sep 4, 2023
df7c508
Merge branch 'master' into pramodcog/UX-1220
pramodcog Sep 4, 2023
3f7028e
Merge refs/heads/master into pramodcog/UX-1220
cognite-bulldozer[bot] Sep 4, 2023
9ee4350
Merge refs/heads/master into pramodcog/UX-1220
cognite-bulldozer[bot] Sep 4, 2023
6b0efb1
Merge refs/heads/master into pramodcog/UX-1220
cognite-bulldozer[bot] Sep 4, 2023
af299e7
Merge refs/heads/master into pramodcog/UX-1220
cognite-bulldozer[bot] Sep 4, 2023
ca92c3f
addressed review comments
pramodcog Sep 4, 2023
113f496
Merge branch 'pramodcog/UX-1220' of https://github.com/cognitedata/re…
pramodcog Sep 4, 2023
69acda9
Merge master into pramodcog/UX-1220
cognite-bulldozer[bot] Sep 4, 2023
f56fb96
test workflow changes
pramodcog Sep 4, 2023
f08f74b
Merge branch 'pramodcog/UX-1220' of https://github.com/cognitedata/re…
pramodcog Sep 4, 2023
0ac8d64
reverted after successful test of workflow
pramodcog Sep 4, 2023
30a1861
Merge master into pramodcog/UX-1220
cognite-bulldozer[bot] Sep 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/locize-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Translation sync added and deleted keys to locize
on: workflow_dispatch

jobs:
locize-sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
always-auth: true

- name: Setup Cognite CICD Yarn
run: |
echo "
npmScopes:
cognite:
npmAlwaysAuth: true
npmAuthToken: \"\${NPM_TOKEN}\"
npmRegistryServer: "https://registry.npmjs.org"
" >> .yarnrc.yml
env:
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

- name: Install NPM dependencies
working-directory: react-components
run: yarn install --immutable
env:
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

- name: 'Save added keys to locize'
working-directory: react-components
run: yarn save-missing
env:
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
LOCIZE_API_KEY: ${{ secrets.LOCIZE_API_KEY }}

- name: 'Remove deleted keys from locize'
working-directory: react-components
run: yarn remove-deleted
env:
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
LOCIZE_API_KEY: ${{ secrets.LOCIZE_API_KEY }}
10 changes: 9 additions & 1 deletion react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"tsc": "tsc",
"lint": "eslint . --cache"
"lint": "eslint . --cache",
"pull-keys": "cdf-i18n-utils-cli pull-keys-from-remote --namespace reveal-react-components --path ./src/common/i18n && yarn sort-keys",
"remove-deleted": "cdf-i18n-utils-cli remove-deleted-keys-from-remote --namespace reveal-react-components --path ./src/common/i18n",
"save-missing": "cdf-i18n-utils-cli save-missing-keys-to-remote --namespace reveal-react-components --path ./src/common/i18n",
"sort-keys": "cdf-i18n-utils-cli sort-local-keys --namespace reveal-react-components --path ./src/common/i18n"
pramodcog marked this conversation as resolved.
Show resolved Hide resolved
},
"peerDependencies": {
"@cognite/cogs.js": ">=9",
Expand All @@ -27,6 +31,8 @@
"@babel/preset-env": "7.22.14",
"@babel/preset-react": "7.22.5",
"@babel/preset-typescript": "7.22.11",
"@cognite/cdf-i18n-utils": "^0.7.5",
"@cognite/cdf-utilities": "^3.4.7",
"@cognite/cogs.js": "^9.17.0",
"@cognite/reveal": "4.4.2",
"@cognite/sdk": "^8.2.0",
Expand All @@ -53,11 +59,13 @@
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "latest",
"locize-cli": "^7.14.6",
"moq.ts": "^10.0.6",
"prettier": "^3.0.0",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-router-dom": "^6.15.0",
"storybook": "7.3.2",
"style-loader": "^3.3.3",
"styled-components": "5.3.11",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"CAD_MODELS": "CAD models",
"POINT_CLOUDS": "Point clouds",
"IMAGES_360": "360 images",
"HIGH_FIDELITY": "High fidelity",
"PAN": "Pan",
"TOUCH_SELECT": "Tap to select",
"TOUCH_ZOOM": "Zoom",
"MOUSE_ZOOM": "Zoom / scroll",
"MOUSE_ROTATE": "Rotate",
"MOUSE_INSTRUCTIONS": "Click+drag",
"MOUSE_SELECT": "Select Objects",
"MOUSE_SELECT_INSTRUCTION": "Click on interactive objects",
"KEYBOARD_DOWN": "Down",
"KEYBOARD_UP": "Up",
"KEYBOARD_FORWARD": "Forward",
"KEYBOARD_BACK": "Back",
"KEYBOARD_RIGHT": "Right",
"KEYBOARD_LEFT": "Left",
"KEYBOARD_LOOK_DOWN": "Look Down",
"KEYBOARD_LOOK_UP": "Look Up",
"KEYBOARD_LOOK_RIGHT": "Look Right",
"KEYBOARD_LOOK_LEFT": "Look Left",
"KEYBOARD_NAVIGATION_TITLE": "Keyboard",
"KEYBOARD_NAVIGATION_SUBTITLE": "Move and look around",
"KEYBOARD_NAVIGATION_DESCRIPTION": "Click and hold to move.\nYou can also use mouse in conjunction with keys.",
"MOUSE_NAVIGATION_TITLE": "Mouse",
"MOUSE_TOUCH_NAVIGATION_SUBTITLE": "Navigate and select",
"MOUSE_NAVIGATION_DESCRIPTION": "Click and drag to rotate, and pan the view. Use mouse wheel to zoom the view. Left click to select",
"TOUCH_NAVIGATION_TITLE": "Touch",
"TOUCH_NAVIGATION_DESCRIPTION": "Use gestures to zoom, pan and select",
"IMAGES_360_STATION": "Station :",
"IMAGES_360_DETAILS": "Details"
}
15 changes: 15 additions & 0 deletions react-components/src/common/i18n/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*!
* Copyright 2023 Cognite AS
*/
import { useTypedTranslation } from '@cognite/cdf-i18n-utils';

import en from './en/reveal-react-components.json';

export const translations = {
en: { 'reveal-react-components': en }
};

export type TranslationKeys = keyof typeof en;

export const useTranslation = (): ReturnType<typeof useTypedTranslation<TranslationKeys>> =>
useTypedTranslation<TranslationKeys>();
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { Chip, Tooltip } from '@cognite/cogs.js';
import { type ReactElement } from 'react';
import styled from 'styled-components';
import { useTranslation } from '../../../common/i18n';

export type Image360HistoricalPanelProps = {
revisionCount?: number;
Expand All @@ -17,6 +18,7 @@ export const Image360HistoricalPanel = ({
revisionDetailsExpanded,
setRevisionDetailsExpanded
}: Image360HistoricalPanelProps): ReactElement => {
const { t } = useTranslation();
const count = revisionCount?.toString();

const onDetailsClick = (): void => {
Expand All @@ -29,12 +31,22 @@ export const Image360HistoricalPanel = ({
<StyledToolBar onClick={onDetailsClick} isExpanded={revisionDetailsExpanded}>
{!revisionDetailsExpanded && (
<>
<StyledChip icon="History" iconPlacement="right" label="Details" hideTooltip />
<StyledChip
icon="History"
iconPlacement="right"
label={t('IMAGES_360_DETAILS')}
hideTooltip
/>
<StyledChipCount label={count} hideTooltip />
</>
)}
{revisionDetailsExpanded && (
<StyledChip icon="PushRight" iconPlacement="right" label="Details" hideTooltip />
<StyledChip
icon="PushRight"
iconPlacement="right"
label={t('IMAGES_360_DETAILS')}
hideTooltip
/>
)}
</StyledToolBar>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Thumbnail } from '../utils/Thumbnail';
import { type Cognite3DViewer, type Image360 } from '@cognite/reveal';
// Using named import to avoid react component creation error when default import is used.
import { uniqueId } from 'lodash';
import { useTranslation } from '../../../common/i18n';

export type Image360RevisionDetails = {
date?: string;
Expand Down Expand Up @@ -38,6 +39,7 @@ export const Image360HistoricalSummary = forwardRef(
}: Image360HistoricalSummaryProps,
ref: React.ForwardedRef<number>
) => {
const { t } = useTranslation();
const gridContainerRef = useRef<HTMLDivElement>(null);

const onRevisionChanged = async (
Expand Down Expand Up @@ -74,7 +76,9 @@ export const Image360HistoricalSummary = forwardRef(
<OverviewContainer>
<StyledFlex direction="column">
<StyledSubFlex>{stationName}</StyledSubFlex>
<StyledDetail>Station: {stationId}</StyledDetail>
<StyledDetail>
{t('IMAGES_360_STATION')} {stationId}
</StyledDetail>
</StyledFlex>

<StyledLayoutGridContainer onScroll={onScroll} ref={gridContainerRef}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ import {
KeyboardNavigationInstructionGrid,
ArrowKeyboardNavigationInstructionGrid
} from './elements';
import { useTranslation } from '../../../common/i18n';

export const KeyboardNavigation = (): ReactElement => {
const { t } = useTranslation();
return (
<Section
title={'Keyboard'}
subTitle={'Move and look around'}
description={'Click and hold to move.\nYou can also use mouse in conjunction with keys.'}>
title={t('KEYBOARD_NAVIGATION_TITLE')}
subTitle={t('KEYBOARD_NAVIGATION_SUBTITLE')}
description={t('KEYBOARD_NAVIGATION_DESCRIPTION')}>
<Flex gap={8} style={{ paddingTop: 12 }}>
<Flex direction="column">
<KeyboardNavigationInstructionGrid>
<InstructionText>Down</InstructionText>
<InstructionText>Forward</InstructionText>
<InstructionText>Up</InstructionText>
<InstructionText> {t('KEYBOARD_DOWN')} </InstructionText>
<InstructionText>{t('KEYBOARD_FORWARD')}</InstructionText>
<InstructionText>{t('KEYBOARD_UP')}</InstructionText>
<QWEASDKeysNavigation.Q />
<QWEASDKeysNavigation.W />
<QWEASDKeysNavigation.E />
Expand All @@ -32,21 +34,21 @@ export const KeyboardNavigation = (): ReactElement => {
<QWEASDKeysNavigation.A />
<QWEASDKeysNavigation.S style={{ marginLeft: 6 }} />
<QWEASDKeysNavigation.D style={{ marginLeft: 6 }} />
<InstructionText>Left</InstructionText>
<InstructionText>Back</InstructionText>
<InstructionText>Right</InstructionText>
<InstructionText>{t('KEYBOARD_LEFT')}</InstructionText>
<InstructionText>{t('KEYBOARD_BACK')}</InstructionText>
<InstructionText>{t('KEYBOARD_RIGHT')}</InstructionText>
</KeyboardNavigationInstructionGrid>
</Flex>
<ArrowKeyboardNavigationInstructionGrid>
<InstructionText>Look Up</InstructionText>
<InstructionText>Look Left</InstructionText>
<InstructionText>{t('KEYBOARD_LOOK_UP')}</InstructionText>
<InstructionText>{t('KEYBOARD_LOOK_LEFT')}</InstructionText>
<ArrowKeysNavigation.Up />
<InstructionText>Look Right</InstructionText>
<InstructionText>{t('KEYBOARD_LOOK_RIGHT')}</InstructionText>
<ArrowKeysNavigation.Left />
<ArrowKeysNavigation.Down />
<ArrowKeysNavigation.Right />
<br />
<InstructionText>Look Down</InstructionText>
<InstructionText>{t('KEYBOARD_LOOK_DOWN')}</InstructionText>
</ArrowKeyboardNavigationInstructionGrid>
</Flex>
</Section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ import {
MouseNavigationCombinedGridItem
} from './elements';
import { Section } from './Section';
import { useTranslation } from '../../../common/i18n';

export const MouseNavigation = (): ReactElement => {
const { t } = useTranslation();
return (
<Section
title={'Mouse'}
subTitle={'Navigate and select'}
description={
'Click and drag to rotate, and pan the view. Use mouse wheel to zoom the view. Left click to select'
}>
title={t('MOUSE_NAVIGATION_TITLE')}
subTitle={t('MOUSE_TOUCH_NAVIGATION_SUBTITLE')}
description={t('MOUSE_NAVIGATION_DESCRIPTION')}>
<MouseNavigationInstructionGrid>
<InstructionText>Zoom / scroll</InstructionText>
<InstructionText>{t('MOUSE_ZOOM')}</InstructionText>
<InstructionText style={{ marginBottom: 30, textAlign: 'right' }}>
Rotate
<InstructionDetail>Click+drag</InstructionDetail>
{t('MOUSE_ROTATE')}
<InstructionDetail>{t('MOUSE_INSTRUCTIONS')}</InstructionDetail>
</InstructionText>
<MouseNavigationCombinedGridItem>
<StyledMouse />
</MouseNavigationCombinedGridItem>
<InstructionText style={{ marginBottom: 30, textAlign: 'left' }}>
Pan
<InstructionDetail>Click+drag</InstructionDetail>
{t('PAN')}
<InstructionDetail>{t('MOUSE_INSTRUCTIONS')}</InstructionDetail>
</InstructionText>
<InstructionText style={{ marginTop: -50, textAlign: 'right' }}>
Select Objects
<InstructionDetail>Click on interactive objects</InstructionDetail>
{t('MOUSE_SELECT')}
<InstructionDetail>{t('MOUSE_SELECT_INSTRUCTION')}</InstructionDetail>
</InstructionText>
</MouseNavigationInstructionGrid>
</Section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@ import {
TouchNavigationInstructionGrid
} from './elements';
import { TouchZoom, TouchPan, TouchSelect } from './Graphics/Touch';
import { useTranslation } from '../../../common/i18n';

export const TouchNavigation = (): ReactElement => {
const { t } = useTranslation();
return (
<Section
title={'Touch'}
subTitle={'Navigate and select'}
description={'Use gestures to zoom, pan and select'}>
title={t('TOUCH_NAVIGATION_TITLE')}
subTitle={t('MOUSE_TOUCH_NAVIGATION_SUBTITLE')}
description={t('TOUCH_NAVIGATION_DESCRIPTION')}>
<TouchNavigationInstructionGrid>
<div>
<TouchPan />
<InstructionText>Pan</InstructionText>
<InstructionText>{t('PAN')}</InstructionText>
</div>
<TouchNavigationCombinedGridItem>
<TouchSelect />
<InstructionText>Tap to select</InstructionText>
<InstructionText>{t('TOUCH_SELECT')}</InstructionText>
</TouchNavigationCombinedGridItem>
<div>
<TouchZoom />
<InstructionText>Zoom</InstructionText>
<InstructionText>{t('TOUCH_ZOOM')}</InstructionText>
</div>
</TouchNavigationInstructionGrid>
</Section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { StyledChipCount, StyledLabel, StyledSubMenu } from './elements';
import { uniqueId } from 'lodash';
import { type Reveal3DResourcesLayersProps } from './types';
import { useRevealContainerElement } from '../../RevealContainer/RevealContainerElementContext';
import { useTranslation } from '../../../common/i18n';

export const CadModelLayersContainer = ({
layerProps
}: {
layerProps: Reveal3DResourcesLayersProps;
}): ReactElement => {
const { t } = useTranslation();
const viewer = useReveal();
const revealContainerElement = useRevealContainerElement();
const [visible, setVisible] = useState(false);
Expand Down Expand Up @@ -109,7 +111,7 @@ export const CadModelLayersContainer = ({
setVisible(true);
}}
/>
<StyledLabel> CAD models </StyledLabel>
<StyledLabel> {t('CAD_MODELS')} </StyledLabel>
<StyledChipCount label={count} hideTooltip type="neutral" />
</Flex>
</Menu.Submenu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { type Image360Collection } from '@cognite/reveal';
import { uniqueId } from 'lodash';
import { type Reveal3DResourcesLayersProps } from './types';
import { useRevealContainerElement } from '../../RevealContainer/RevealContainerElementContext';
import { useTranslation } from '../../../common/i18n';

export const Image360CollectionLayerContainer = ({
layerProps
}: {
layerProps: Reveal3DResourcesLayersProps;
}): ReactElement => {
const { t } = useTranslation();
const viewer = useReveal();
const revealContainerElement = useRevealContainerElement();
const [visible, setVisible] = useState(false);
Expand Down Expand Up @@ -105,7 +107,7 @@ export const Image360CollectionLayerContainer = ({
setVisible(true);
}}
/>
<StyledLabel> 360 images </StyledLabel>
<StyledLabel> {t('IMAGES_360')} </StyledLabel>
<StyledChipCount label={count} hideTooltip type="neutral" />
</Flex>
</Menu.Submenu>
Expand Down
Loading
Loading