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

V2 translate #6569

Draft
wants to merge 88 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
4f1f348
translations atom
Zasa-san Mar 6, 2024
1402b90
migrate Translate WIP
Zasa-san Mar 6, 2024
d8dbc10
Merge branch 'development' into v2-translate
Zasa-san Mar 12, 2024
6ee267f
Merge branch 'development' into v2-translate
Zasa-san Mar 13, 2024
6ca6e91
handle inline edit mode
Zasa-san Mar 13, 2024
97b6381
stop event
Zasa-san Mar 13, 2024
b88ad18
Merge branch 'development' into v2-translate
Zasa-san Mar 18, 2024
07a6f03
Merge branch 'development' into v2-translate
Zasa-san Mar 20, 2024
77c9882
Merge branch 'development' into v2-translate
Zasa-san Mar 22, 2024
cbb3310
Merge branch 'development' into v2-translate
Zasa-san Mar 22, 2024
d261f87
adds update translations endpoint
mfacar Mar 22, 2024
4987ccc
wip modal form
Zasa-san Apr 10, 2024
c22f8e4
get translations V2 WIP
mfacar Apr 10, 2024
900e765
Merge branch 'development' of https://github.com/huridocs/uwazi into …
mfacar Apr 10, 2024
fe426e7
Merge branch 'development' into v2-translate
Zasa-san Apr 12, 2024
2530799
Merge branch 'development' into v2-translate
Zasa-san Apr 12, 2024
6057563
Merge branch 'development' of https://github.com/huridocs/uwazi into …
Zasa-san Apr 22, 2024
44bc9b1
Merge branch 'development' into v2-translate
Zasa-san Apr 29, 2024
d9f71d8
Merge branch 'development' of https://github.com/huridocs/uwazi into …
Zasa-san May 15, 2024
c7a07d0
Merge branch 'development' of https://github.com/huridocs/uwazi into …
Zasa-san May 16, 2024
011be44
Merge branch 'development' of https://github.com/huridocs/uwazi into …
Zasa-san May 21, 2024
4a3bb7b
Merge branch 'development' of https://github.com/huridocs/uwazi into …
Zasa-san May 21, 2024
e55a018
Merge branch 'development' into v2-translate
Zasa-san May 23, 2024
f69ee77
Merge branch 'development' into v2-translate
Zasa-san Jun 3, 2024
0b4ca31
Merge branch 'development' into v2-translate
Zasa-san Jun 4, 2024
ea9094c
Merge branch 'development' into v2-translate
Zasa-san Jun 4, 2024
166a6fc
Merge branch 'development' into v2-translate
Zasa-san Jun 4, 2024
9978be6
Merge branch 'development' into v2-translate
Zasa-san Jun 6, 2024
1f43323
Merge branch 'development' into v2-translate
Zasa-san Jun 6, 2024
2262919
Merge branch 'development' into v2-translate
Zasa-san Jun 9, 2024
661ba10
Merge branch 'development' into v2-translate
Zasa-san Jun 10, 2024
3efa166
Merge branch 'development' into v2-translate
Zasa-san Jun 11, 2024
9f5a9f2
Merge branch 'development' into v2-translate
Zasa-san Jun 12, 2024
d64fe0d
Merge branch 'development' into v2-translate
Zasa-san Jun 13, 2024
dc256a7
Merge branch 'development' into v2-translate
Zasa-san Jun 14, 2024
60c2edf
Merge branch 'development' into v2-translate
Zasa-san Jun 16, 2024
3d6d693
Merge branch 'development' into v2-translate
Zasa-san Jun 16, 2024
e5ee66b
Merge branch 'development' into v2-translate
Zasa-san Jun 18, 2024
4a39595
Merge branch 'development' into v2-translate
Zasa-san Jun 18, 2024
daf1a87
Merge branch 'development' into v2-translate
Zasa-san Jun 19, 2024
2fa92c2
Merge branch 'development' into v2-translate
Zasa-san Jun 24, 2024
715737d
Merge branch 'development' into v2-translate
Zasa-san Jun 24, 2024
24ce3c5
Merge branch 'development' into v2-translate
Zasa-san Jun 25, 2024
f484920
Merge branch 'development' into v2-translate
Zasa-san Jun 25, 2024
7936bec
Merge branch 'development' into v2-translate
Zasa-san Jun 27, 2024
e17a671
Merge branch 'development' into v2-translate
Zasa-san Jun 28, 2024
8d9a299
Merge branch 'development' into v2-translate
Zasa-san Jul 3, 2024
f78d994
Merge branch 'development' into v2-translate
Zasa-san Jul 3, 2024
3c6dc0e
Merge branch 'development' into v2-translate
Zasa-san Jul 16, 2024
d0a84f9
Merge branch 'development' into v2-translate
Zasa-san Jul 21, 2024
1d622fc
Merge branch 'development' into v2-translate
Zasa-san Jul 23, 2024
06de907
Merge branch 'development' into v2-translate
Zasa-san Jul 25, 2024
19039e6
Merge branch 'development' into v2-translate
Zasa-san Aug 1, 2024
d00e858
Merge branch 'development' into v2-translate
Zasa-san Aug 2, 2024
a61f64e
Merge branch 'development' into v2-translate
Zasa-san Aug 7, 2024
121c699
Merge branch 'development' into v2-translate
Zasa-san Aug 12, 2024
0e35d51
Merge branch 'development' into v2-translate
Zasa-san Aug 15, 2024
8db958c
Merge branch 'development' into v2-translate
Zasa-san Aug 20, 2024
f794b1b
Merge branch 'development' into v2-translate
Zasa-san Aug 22, 2024
f787dc3
Merge branch 'development' into v2-translate
Zasa-san Aug 30, 2024
4a92690
Merge branch 'development' into v2-translate
Zasa-san Sep 3, 2024
45ca4bd
Merge branch 'development' into v2-translate
Zasa-san Sep 4, 2024
dc1a1cb
Translate component using translationsAtom and loading correct values…
konzz Sep 4, 2024
007773a
Merge branch 'development' into v2-translate
Zasa-san Sep 11, 2024
ed947a9
test new endpoint
Zasa-san Sep 11, 2024
91ff794
Merge branch 'development' of https://github.com/huridocs/uwazi into …
Zasa-san Sep 11, 2024
83cf08f
Merge branch 'development' into v2-translate
Zasa-san Sep 17, 2024
285b30b
correctly set form
Zasa-san Sep 18, 2024
8878777
Merge branch 'development' of https://github.com/huridocs/uwazi into …
Zasa-san Sep 25, 2024
73788b6
Merge branch 'development' into v2-translate
Zasa-san Sep 25, 2024
35d6427
Merge branch 'development' into v2-translate
Zasa-san Oct 2, 2024
5437171
context to post request
josh-huridocs Oct 2, 2024
3b38af0
Merge branch 'development' of https://github.com/huridocs/uwazi into …
mfacar Oct 13, 2024
549248b
Merge branch 'v2-translate' of https://github.com/huridocs/uwazi into…
mfacar Oct 13, 2024
be34a6c
update translate atom after update
mfacar Oct 14, 2024
ff0ed47
uses context by language
mfacar Oct 14, 2024
35d01ec
Merge branch 'development' of https://github.com/huridocs/uwazi into …
mfacar Oct 16, 2024
92b822e
look & feel + socket events
mfacar Oct 17, 2024
ca4d6c7
Merge branch 'development' of https://github.com/huridocs/uwazi into …
mfacar Oct 17, 2024
55f2e39
ci fixes
mfacar Oct 17, 2024
83d7dfe
migrate t and update cache reset strategy
Zasa-san Oct 30, 2024
1d547ef
Merge branch 'development' of https://github.com/huridocs/uwazi into …
Zasa-san Oct 30, 2024
496e55b
Merge branch 'development' into v2-translate
Zasa-san Nov 13, 2024
2cab6e5
update affected files
josh-huridocs Nov 13, 2024
de42dcc
adjust zindex and use t function for texts inside
josh-huridocs Nov 13, 2024
ba8c3f0
Merge branch 'development' into v2-translate
Zasa-san Nov 18, 2024
9702a33
migrate I18Nmenu
Zasa-san Nov 18, 2024
663e3e1
remove icon dependency
Zasa-san Nov 18, 2024
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
50 changes: 50 additions & 0 deletions app/api/i18n/routes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-lines */
import { createError, validation } from 'api/utils';
import settings from 'api/settings';
import entities from 'api/entities';
Expand All @@ -11,6 +12,7 @@ import { Application, Request } from 'express';
import { UITranslationNotAvailable } from 'api/i18n/defaultTranslations';
import needsAuthorization from '../auth/authMiddleware';
import translations from './translations';
import { getTranslationsEntriesV2, upsertTranslationEntries } from './v2_support';

const addLanguage = async (language: LanguageSchema) => {
const newSettings = await settings.addLanguage(language);
Expand Down Expand Up @@ -59,6 +61,7 @@ async function deleteLanguage(key: LanguageISO6391, req: Request) {

type TranslationsRequest = Request & { query: { context: string } };

// eslint-disable-next-line max-statements
export default (app: Application) => {
app.get(
'/api/translations',
Expand All @@ -81,6 +84,14 @@ export default (app: Application) => {
}
);

app.get('/api/translationsV2', async (_req: TranslationsRequest, res) => {
const translationsV2 = await getTranslationsEntriesV2();

const translationList = await translationsV2.all();

res.json(translationList);
});

app.get('/api/languages', async (_req, res) => {
res.json(await translations.availableLanguages());
});
Expand Down Expand Up @@ -158,6 +169,45 @@ export default (app: Application) => {
}
);

app.post(
'/api/translationsV2',
needsAuthorization(),
validation.validateRequest({
type: 'object',
properties: {
body: {
type: 'array',
items: {
type: 'object',
properties: {
_id: { type: 'string' },
language: { type: 'string' },
key: { type: 'string' },
value: { type: 'string' },
context: {
type: 'object',
properties: {
id: { type: 'string' },
label: { type: 'string' },
type: { type: 'string' },
},
required: ['id', 'label', 'type'],
},
},
required: ['language', 'key', 'value', 'context'],
},
},
},
required: ['body'],
}),
async (req, res) => {
await upsertTranslationEntries(req.body);
req.sockets.emitToCurrentTenant('translationKeysChange', req.body);
res.status(200);
res.json({ success: true });
}
);

app.post(
'/api/translations/populate',
needsAuthorization(),
Expand Down
26 changes: 26 additions & 0 deletions app/api/i18n/specs/routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TestEmitSources, iosocket, setUpApp } from 'api/utils/testingRoutes';
import { availableLanguages } from 'shared/languagesList';
import { LanguageSchema } from 'shared/types/commonTypes';
import { UserRole } from 'shared/types/userSchema';
import { TranslationContext, TranslationType } from 'shared/translationType';
import { DefaultTranslations } from '../defaultTranslations';
import { sortByLocale } from './sortByLocale';

Expand Down Expand Up @@ -229,6 +230,31 @@ describe('i18n translations routes', () => {
});
});

describe('api/translationsV2', () => {
it('should update the translations', async () => {
const response = await request(app)
.post('/api/translationsV2')
.send([
{
language: 'es',
key: 'Search',
value: 'Búsqueda',
context: {
id: 'System',
label: 'User Interface',
type: 'Uwazi UI',
},
},
]);
const systemTranslations = response.body
.find((language: TranslationType) => language.locale === 'es')
.contexts.find((context: TranslationContext) => context.id === 'System');
expect(systemTranslations).toMatchObject({
values: { Search: 'Búsqueda' },
});
});
});

describe('api/translations/languages', () => {
describe('when successful', () => {
let response: request.Response;
Expand Down
22 changes: 13 additions & 9 deletions app/api/i18n/v2_support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const createTranslationsV2 = async (translation: TranslationType) => {
).create(flattenTranslations(translation));
};

export const upsertTranslationsV2 = async (translations: TranslationType[]) => {
export const upsertTranslationEntries = async (translations: CreateTranslationsData[]) => {
const transactionManager = DefaultTransactionManager();
await new UpsertTranslationsService(
DefaultTranslationsDataSource(transactionManager),
Expand All @@ -120,12 +120,15 @@ export const upsertTranslationsV2 = async (translations: TranslationType[]) => {
DefaultSettingsDataSource(transactionManager)
),
transactionManager
).upsert(
translations.reduce<CreateTranslationsData[]>(
(flattened, t) => flattened.concat(flattenTranslations(t)),
[]
)
).upsert(translations);
};

export const upsertTranslationsV2 = async (translations: TranslationType[]) => {
const translationsToUpsert = translations.reduce<CreateTranslationsData[]>(
(flattened, t) => flattened.concat(flattenTranslations(t)),
[]
);
return upsertTranslationEntries(translationsToUpsert);
};

export const deleteTranslationsByContextIdV2 = async (contextId: string) => {
Expand Down Expand Up @@ -159,10 +162,11 @@ export const getTranslationsV2ByLanguage = async (language: LanguageISO6391) =>
language
);

export const getTranslationsEntriesV2 = async () =>
new GetTranslationsService(DefaultTranslationsDataSource(DefaultTransactionManager())).getAll();

export const getTranslationsV2 = async () =>
resultsToV1TranslationType(
new GetTranslationsService(DefaultTranslationsDataSource(DefaultTransactionManager())).getAll()
);
resultsToV1TranslationType(await getTranslationsEntriesV2());

export const updateContextV2 = async (
context: CreateTranslationsData['context'],
Expand Down
4 changes: 4 additions & 0 deletions app/react/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { socket } from 'app/socket';
import { NotificationsContainer } from 'V2/Components/UI';
import { Matomo, CleanInsights } from 'app/V2/Components/Analitycs';
import { settingsAtom } from 'V2/atoms/settingsAtom';
import { TranslateModal } from 'app/I18N/components/TranslateModal';
import { inlineEditAtom } from 'V2/atoms';
import Confirm from './Confirm';
import { Menu } from './Menu';
import { AppMainContext } from './AppMainContext';
Expand All @@ -26,6 +28,7 @@ import 'flowbite';

const App = ({ customParams }) => {
const [showMenu, setShowMenu] = useState(false);
const [inlineEditState] = useAtom(inlineEditAtom);
const [confirmOptions, setConfirmOptions] = useState({});
const [settings, setSettings] = useAtom(settingsAtom);

Expand Down Expand Up @@ -101,6 +104,7 @@ const App = ({ customParams }) => {
</main>
</div>
<NotificationsContainer />
{inlineEditState.inlineEdit && inlineEditState.context && <TranslateModal />}
</div>
);
};
Expand Down
10 changes: 1 addition & 9 deletions app/react/App/scss/layout/_header.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use "sass:color";
@use 'sass:color';

@import '../config/colors';
@import '../elements/tooltip';
Expand Down Expand Up @@ -254,14 +254,6 @@ header {
}
}

.live-on {
color: #88eacd;
}

.live-off {
color: #ffe66b;
}

button.singleItem {
padding-left: 1em;
}
Expand Down
32 changes: 25 additions & 7 deletions app/react/App/sockets.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { actions } from 'app/BasicReducer';
import { t, Translate } from 'app/I18N';
import { t } from 'app/I18N';
import { notificationActions } from 'app/Notifications';
import { documentProcessed } from 'app/Uploads/actions/uploadsActions';
import { atomStore, translationsAtom } from 'V2/atoms';
import { store } from '../store';
import { socket, reconnectSocket } from '../socket';

Expand Down Expand Up @@ -58,10 +59,27 @@ socket.on('thesauriDelete', thesauri => {
store.dispatch(actions.remove('thesauris', { _id: thesauri.id }));
});

socket.on('translationsChange', translations => {
store.dispatch(actions.update('translations', translations, 'locale'));
t.resetCachedTranslation();
Translate.resetCachedTranslation();
socket.on('translationsChange', languageTranslations => {
const translations = atomStore.get(translationsAtom);
const modifiedLanguage = translations.find(
translation => translation.locale === languageTranslations.locale
);
modifiedLanguage.contexts = languageTranslations.contexts;
atomStore.set(translationsAtom, translations);
//t.resetCachedTranslation();
// Translate.resetCachedTranslation();
});

socket.on('translationKeysChange', translationsEntries => {
const translations = atomStore.get(translationsAtom);
translationsEntries.forEach(item => {
const modifiedContext = translations
.find(translation => translation.locale === item.language)
.contexts.find(c => c.id && c.id === item.context.id);
modifiedContext.values[item.key] = item.value;
});
atomStore.set(translationsAtom, translations);
//t.resetCachedTranslation();
});

socket.on('translationsInstallDone', () => {
Expand Down Expand Up @@ -89,8 +107,8 @@ socket.on('translationsInstallError', errorMessage => {

socket.on('translationsDelete', locale => {
store.dispatch(actions.remove('translations', { locale }, 'locale'));
t.resetCachedTranslation();
Translate.resetCachedTranslation();
//t.resetCachedTranslation();
// Translate.resetCachedTranslation();
});

socket.on('translationsDeleteDone', () => {
Expand Down
Loading
Loading