-
Notifications
You must be signed in to change notification settings - Fork 21
Add multi-language authoring support (Web changes) #2859
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,13 @@ const Endpoints = { | |
| }, | ||
| EngagementTranslations: { | ||
| GET_TRANSLATION_LANGUAGES: `${AppConfig.apiUrl}/engagement/engagement_id/translations/languages`, | ||
| GET_BY_LANGUAGE: `${AppConfig.apiUrl}/engagement/engagement_id/translations/language/language_id`, | ||
| CREATE: `${AppConfig.apiUrl}/engagement/engagement_id/translations/`, | ||
| PATCH: `${AppConfig.apiUrl}/engagement/engagement_id/translations/engagement_translation_id`, | ||
| }, | ||
| EngagementContentTranslations: { | ||
| GET_BY_LANGUAGE: `${AppConfig.apiUrl}/engagement/engagement_id/content/translations/language/language_id`, | ||
| UPDATE_BY_LANGUAGE: `${AppConfig.apiUrl}/engagement/engagement_id/content/translations/language/language_id`, | ||
| }, | ||
| EngagementMetadata: { | ||
| GET_BY_ENG: `${AppConfig.apiUrl}/engagements/engagement_id/metadata`, | ||
|
|
@@ -126,6 +133,9 @@ const Endpoints = { | |
| GET_LIST: `${AppConfig.apiUrl}/contacts/`, | ||
| CREATE: `${AppConfig.apiUrl}/contacts/`, | ||
| UPDATE: `${AppConfig.apiUrl}/contacts/`, | ||
| GET_TRANSLATION: `${AppConfig.apiUrl}/contact_translations/contact/contact_id/language/language_id`, | ||
| CREATE_TRANSLATION: `${AppConfig.apiUrl}/contact_translations/`, | ||
| UPDATE_TRANSLATION: `${AppConfig.apiUrl}/contact_translations/translation_id`, | ||
| }, | ||
| Documents: { | ||
| GET_LIST: `${AppConfig.apiUrl}/widgets/widget_id/documents`, | ||
|
|
@@ -146,6 +156,9 @@ const Endpoints = { | |
| UPDATE: `${AppConfig.apiUrl}/widgets/widget_id/events/event_id/item/item_id`, | ||
| DELETE: `${AppConfig.apiUrl}/widgets/widget_id/events/event_id`, | ||
| SORT: `${AppConfig.apiUrl}/widgets/widget_id/events/sort_index`, | ||
| GET_ITEM_TRANSLATION: `${AppConfig.apiUrl}/events/event_id/translations/item/event_item_id/language/language_id`, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be good to have a method that gets an entire list of file translations. |
||
| CREATE_ITEM_TRANSLATION: `${AppConfig.apiUrl}/events/event_id/translations/`, | ||
| UPDATE_ITEM_TRANSLATION: `${AppConfig.apiUrl}/events/event_id/translations/translation_id`, | ||
| }, | ||
| Maps: { | ||
| GET_LIST: `${AppConfig.apiUrl}/widgets/widget_id/maps`, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { Params } from 'react-router'; | ||
| import { getEngagement } from 'services/engagementService'; | ||
| import { getAvailableTranslationLanguages, getEngagement } from 'services/engagementService'; | ||
| import { getEngagementIdBySlug, getSlugByEngagementId } from 'services/engagementSlugService'; | ||
| import { getWidgets } from 'services/widgetService'; | ||
| import { getEngagementMetadata, getMetadataTaxa } from 'services/engagementMetadataService'; | ||
|
|
@@ -9,7 +9,6 @@ import { getTeamMembers } from 'services/membershipService'; | |
| import { EngagementTeamMember } from 'models/engagementTeamMember'; | ||
| import { EngagementDetailsTab } from 'models/engagementDetailsTab'; | ||
| import { getDetailsTabs } from 'services/engagementDetailsTabService'; | ||
| import { getTenantLanguages } from 'services/languageService'; | ||
| import { Language } from 'models/language'; | ||
|
|
||
| export type EngagementLoaderAdminData = { | ||
|
|
@@ -26,17 +25,30 @@ export type EngagementLoaderAdminData = { | |
| export const engagementLoaderAdmin = async ({ params }: { params: Params<string> }) => { | ||
| const { slug: slugParam, engagementId } = params; | ||
|
|
||
| const tenantId = | ||
| typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined' | ||
| ? window.sessionStorage.getItem('tenantId') | ||
| : null; | ||
| const languages = tenantId ? getTenantLanguages(tenantId) : Promise.resolve([]); | ||
| const slug = slugParam | ||
| ? Promise.resolve(slugParam) | ||
| : getSlugByEngagementId(Number(engagementId)).then((response) => response.slug); | ||
| const engagement = slugParam | ||
| ? getEngagementIdBySlug(slugParam).then((response) => getEngagement(response.engagement_id)) | ||
| : getEngagement(Number(engagementId)); | ||
| const languages = engagement.then((response) => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice safety net for the English language here. Is it for legacy support or could new engagements be missing this value as well? |
||
| getAvailableTranslationLanguages(response.id).then((availableLanguages) => { | ||
| const hasEnglish = availableLanguages.some((language) => language.code === 'en'); | ||
| if (hasEnglish) { | ||
| return availableLanguages; | ||
| } | ||
|
|
||
| return [ | ||
| { | ||
| id: 0, | ||
| code: 'en', | ||
| name: 'English', | ||
| right_to_left: false, | ||
| }, | ||
| ...availableLanguages, | ||
| ]; | ||
| }), | ||
| ); | ||
| const widgets = engagement.then((response) => getWidgets(Number(response.id))); | ||
| const details = engagement.then((response) => getDetailsTabs(response.id)); | ||
| const engagementMetadata = engagement.then((response) => getEngagementMetadata(Number(response.id))); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,7 +10,6 @@ import { colors } from 'styles/Theme'; | |||||||||||
| import { useFormContext } from 'react-hook-form'; | ||||||||||||
| import { Language } from 'models/language'; | ||||||||||||
| import MultiSelect from './MultiSelect'; | ||||||||||||
| import { SystemMessage } from 'components/common/Layout/SystemMessage'; | ||||||||||||
| import { LanguageLoaderData } from './LanguageLoader'; | ||||||||||||
| import { Awaited } from 'utils'; | ||||||||||||
| import { ROUTES, getPath } from 'routes/routes'; | ||||||||||||
|
|
@@ -38,6 +37,12 @@ export const LanguageManager = () => { | |||||||||||
| return false; | ||||||||||||
| }; | ||||||||||||
| const isSingleLanguage = determineSingleLanguage(selectedLanguages); | ||||||||||||
| let languageTypeValue = ''; | ||||||||||||
| if (isSingleLanguage === true) { | ||||||||||||
| languageTypeValue = 'single'; | ||||||||||||
| } else if (isSingleLanguage === false) { | ||||||||||||
| languageTypeValue = 'multi'; | ||||||||||||
|
Comment on lines
+41
to
+44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| useEffect(() => { | ||||||||||||
| fetcher.load(`${getPath(ROUTES.LANGUAGES)}/`); | ||||||||||||
|
|
@@ -62,15 +67,12 @@ export const LanguageManager = () => { | |||||||||||
| }} | ||||||||||||
| aria-label="Select Engagement's Language Type" | ||||||||||||
| name="languageType" | ||||||||||||
| value={isSingleLanguage && (isSingleLanguage ? 'single' : 'multi')} | ||||||||||||
| value={languageTypeValue} | ||||||||||||
| > | ||||||||||||
| <FormControlLabel value={'single'} control={<Radio />} label="English Only" /> | ||||||||||||
| <FormControlLabel value={'multi'} control={<Radio />} label="Multi-language" /> | ||||||||||||
| </RadioGroup> | ||||||||||||
| <When condition={isSingleLanguage === false}> | ||||||||||||
| <SystemMessage status="warning"> | ||||||||||||
| Under construction - this setting currently has no effect | ||||||||||||
| </SystemMessage> | ||||||||||||
| <MultiSelect<Language> | ||||||||||||
| containerProps={{ sx: { mt: 2 } }} | ||||||||||||
| onChange={(_, language, reason) => { | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool stuff Nat, great job on this ticket.