Skip to content

Commit 47bccb7

Browse files
authored
Merge pull request #486 from AppQuality/i18n-translations
feat(i18n): add ach language only in dev mode
2 parents 887ec2f + 5f17ba5 commit 47bccb7

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
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: () => {
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { useMatches } from 'react-router-dom';
2+
import i18n from 'src/i18n';
23

34
export const usePathWithoutLocale = () => {
4-
const [locale, ...matches] = useMatches();
5+
const [, ...matches] = useMatches();
6+
const currentLanguage = i18n.language === 'en' ? '' : `/${i18n.language}`;
7+
58
if (!matches.length) return false;
6-
return matches[matches.length - 1].pathname.replace(locale.pathname, '');
9+
10+
return matches[matches.length - 1].pathname.replace(currentLanguage, '');
711
};

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)