Skip to content

Commit 8863812

Browse files
committed
feat(i18n): add ach language only in dev mode
In order to allow inContext translation we've to add a fake internal language hosting all the meta info
1 parent 3ef90be commit 8863812

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

src/common/getStrapiData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ServiceResponse,
88
} from 'src/features/backoffice';
99
import { StrapiIcon } from 'src/features/backoffice/strapi';
10+
import { isDev } from './isDevEnvironment';
1011

1112
export type StrapiResponse =
1213
| CategoryListResponse
@@ -26,15 +27,14 @@ export type StrapiResponse =
2627
* @returns {object | false}
2728
*/
2829
export const extractStrapiData = (item: StrapiResponse) => {
29-
const isDev = ['staging', 'local'].includes(react_env.REACT_APP_ENV);
3030
if (item !== undefined && item.data !== null) {
3131
if (item.data !== undefined && item.data !== null) {
3232
if (Array.isArray(item.data)) {
3333
const items: any = [];
3434
item.data.forEach((listItem) => {
3535
const newListItem = extractStrapiData({ data: listItem });
3636
if (newListItem) {
37-
if (isDev || newListItem.publishedAt !== null) {
37+
if (isDev() || newListItem.publishedAt !== null) {
3838
items.push(newListItem);
3939
}
4040
}

src/common/isDevEnvironment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const isDev = () =>
2+
['staging', 'local'].includes(react_env.REACT_APP_ENV);

src/features/navigation/Navigation.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { prepareGravatar, isMaxMedia } from 'src/common/utils';
2121
import { useEffect } from 'react';
2222
import API from 'src/common/api';
2323
import TagManager from 'react-gtm-module';
24+
import { isDev } from 'src/common/isDevEnvironment';
2425
import { Changelog } from './Changelog';
2526
import { useGetWorkspacesByWidProjectsQuery } from '../api';
2627
import { getWorkspaceFromLS, saveWorkspaceToLs } from './cachedStorage';
@@ -142,6 +143,7 @@ export const Navigation = ({
142143
key: 'it',
143144
label: t('__APP_LANGUANGE_IT_TEXT'),
144145
},
146+
...(isDev() && { ach: { key: 'ach', label: 'Acholi' } }),
145147
},
146148
currentLanguage: i18n.language,
147149
feedbackTitle: t('__PROFILE_MODAL_FEEDBACK_TITLE'),
@@ -158,11 +160,13 @@ export const Navigation = ({
158160
url: 'https://www.iubenda.com/privacy-policy/833252/full-legal',
159161
},
160162
onSelectLanguage: (lang: string) => {
161-
if (!pathWithoutLocale) return;
163+
if (pathWithoutLocale === false) return;
164+
if (lang === i18n.language) return;
165+
162166
if (lang === 'en') {
163167
document.location.href = pathWithoutLocale;
164168
} else {
165-
document.location.href = `/${lang}/${pathWithoutLocale}`;
169+
document.location.href = `/${lang}${pathWithoutLocale}`;
166170
}
167171
},
168172
onToggleChat: () => {

src/i18n.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import enLinks from './locales/en/links.json';
66
import en from './locales/en/translation.json';
77
import itLinks from './locales/it/links.json';
88
import it from './locales/it/translation.json';
9+
import ach from './locales/ach/translation.json';
10+
import { isDev } from './common/isDevEnvironment';
911

1012
// the translations
1113
// (tip move them in a JSON file and import them)
@@ -16,6 +18,7 @@ countries.registerLocale(require('i18n-iso-countries/langs/es.json'));
1618
const resources = {
1719
en: { translation: en, links: enLinks },
1820
it: { translation: it, links: itLinks },
21+
...(isDev() && { ach: { translation: ach, links: {} } }),
1922
};
2023

2124
i18n
@@ -31,7 +34,7 @@ i18n
3134
returnEmptyString: false,
3235
nsSeparator: false,
3336
resources,
34-
supportedLngs: ['it', 'en'],
37+
supportedLngs: ['it', 'en', ...(isDev() ? ['ach'] : [])],
3538
fallbackLng: 'en',
3639
keySeparator: ':::',
3740
interpolation: {

0 commit comments

Comments
 (0)