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

Translations v1 #1505

Open
wants to merge 29 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1b4e553
Adding translations-button to post-head
Angamanga Nov 13, 2024
08e07da
Adding post-translations component
Angamanga Nov 13, 2024
78fc846
Fix language-length check
Angamanga Nov 13, 2024
56a9962
Translations component for posts
Angamanga Nov 13, 2024
0cc52ef
Moving permissions-check
Angamanga Nov 13, 2024
4eb4c93
Sending base-language when saving a post
Angamanga Dec 4, 2024
a19fec4
Displaying existing post-translations in the translation-edit view
Angamanga Dec 4, 2024
3e2d960
Saving translations properly
Angamanga Dec 9, 2024
2ac1c9d
Displaying translations in post-details
Angamanga Dec 10, 2024
6f8cb9d
Fixing error when saving translations
Angamanga Dec 11, 2024
0dd66fb
New alert for success/info
Angamanga Dec 12, 2024
caeb140
Info/alert-box in posts when showing a translated post
Angamanga Dec 12, 2024
53cfa3f
Displaying post in translated language after saving post
Angamanga Dec 12, 2024
08850aa
Displaying survey-questions in selected language if available
Angamanga Dec 12, 2024
786a080
Merge branch 'development' into USH-1595-translations
Angamanga Dec 13, 2024
fe9b901
Hiding translation-icon in list
Angamanga Dec 13, 2024
3cc3a57
Preserving translations when editing a post
Angamanga Dec 13, 2024
edb49c0
Using full language-list for post-translations
Angamanga Dec 13, 2024
789abfa
Adding validation+small style-fixes
Angamanga Dec 16, 2024
42c54a4
CSS-cleanup for post-translations
Angamanga Dec 16, 2024
6fc8786
Moving strings to en.json
Angamanga Dec 16, 2024
928c329
Removing console.log
Angamanga Dec 16, 2024
f1d50b9
Using site-language if no base_language is set
Angamanga Dec 18, 2024
5f2f268
Hiding translations-icon everywhere except in details
Angamanga Dec 18, 2024
7333f3f
Adding strings to en.json
Angamanga Dec 18, 2024
495122b
Displaying translation-info in post-modal
Angamanga Dec 18, 2024
98f50da
Using full language-list for translations
Angamanga Dec 18, 2024
0eb4f9f
Only displaying icon if translations are available (for non-edit-users)
Angamanga Dec 18, 2024
e9a5bf6
Remove line under dropdown but keep spacing
Angamanga Dec 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
1 change: 1 addition & 0 deletions apps/web-mzima-client/src/app/core/enums/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ export enum Icons {
thumbUp = 'thumb-up',
ellipses = 'ellipses',
lock = 'lock',
translate = 'translate',
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const enum EventType {
RefreshSurveysCounters = 'REFRESH_SURVEYS_COUNTERS',
StopExportPolling = 'STOP_EXPORT_POLLING',
ExportDone = 'EXPORT_DONE',
DisplayTranslatedPost = 'DISPLAY_TRANSLATED_POST',
StatusChange = 'STATUS_CHANGE',
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject } from 'rxjs';
import { LanguageInterface } from '@mzima-client/sdk';
import LangJSON from '../../../assets/locales/languages.json';
import entityLanguages from '../../../assets/locales/entity-languages.json';
import { SessionService } from './session.service';

@Injectable({
Expand Down Expand Up @@ -41,6 +42,9 @@ export class LanguageService {
private set initialLanguage(value: string) {
localStorage.setItem(this.languageKey, value);
}
getEntityLanguages() {
return entityLanguages;
}

getLanguages(): LanguageInterface[] {
if (LangJSON.languages && LangJSON.languages.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,43 @@
[deleteable]="post.allowed_privileges.includes('delete')"
(statusChanged)="statusChangedHandle()"
(deleted)="deletedHandle()"
(openTranslationModal)="openTranslatePost()"
>
</app-post-head>
</div>

<app-post-translated
*ngIf="displayLanguage"
(openTranslationModal)="openTranslatePost()"
(displayOriginalPost)="displayOriginalPost()"
[baseLanguage]="post.base_language"
[displayLanguage]="displayLanguage"
></app-post-translated>
<div class="post__twitter" *ngIf="post.source === 'Twitter' && post.data_source_message_id">
<app-twitter-widget [id]="post.data_source_message_id"></app-twitter-widget>
</div>

<div class="post__survey" *ngIf="post.form">
<h3>{{ post.form.name }}</h3>
<p>{{ post.form.description }}</p>
<h3>{{ post.form.translations[displayLanguage]?.name || post.form.name }}</h3>
<p>{{ post.form.translations[displayLanguage]?.description || post.form.description }}</p>
</div>

<h2 *ngIf="post.title?.length || post.content?.length" data-qa="postTitleValue">
{{ post.title || post.content }}
{{
post.translations[displayLanguage]?.title ||
post.title ||
post.translations[displayLanguage]?.description ||
post.content
}}
</h2>
<div class="post__metadata-container">
<app-post-metadata *ngIf="post.id" [post]="post"></app-post-metadata>
</div>

<div class="post__description" *ngIf="post.title?.length && post.content?.length">
<p [innerHTML]="post.content" data-qa="postDescriptionValue"></p>
<p
[innerHTML]="post.translations[displayLanguage]?.description || post.content"
data-qa="postDescriptionValue"
></p>
</div>

<ng-container *ngFor="let post_content of post.post_content; let i = index">
Expand All @@ -60,7 +75,7 @@ <h2 *ngIf="post.title?.length || post.content?.length" data-qa="postTitleValue">
*ngIf="field.input !== 'tags' ? field.value : field.value?.length"
class="post__group"
>
<h3>{{ field.label }}</h3>
<h3>{{ field.translations[displayLanguage]?.label || field.label }}</h3>

<ng-container *ngIf="field.input === 'tags'">
<ng-container *ngFor="let category of field.value">
Expand Down Expand Up @@ -121,12 +136,21 @@ <h3>{{ field.label }}</h3>
<p *ngIf="!field.value.value">-</p>
</ng-container>
<ng-container *ngIf="field.label !== 'Media Link'">
<p>{{ field.value.value || '-' }}</p>
<p>
{{
field.value.translations[displayLanguage]?.value || field.value.value || '-'
}}
</p>
</ng-container>
</ng-container>

<ng-container *ngIf="field.input === 'textarea'">
<p [innerHTML]="field.value.value" data-qa="longTextValue"></p>
<p
[innerHTML]="
field.value.translations[displayLanguage]?.value || field.value.value
"
data-qa="longTextValue"
></p>
</ng-container>

<ng-container *ngIf="field.input === 'checkbox'">
Expand Down Expand Up @@ -228,7 +252,9 @@ <h3>{{ field.label }}</h3>

<ng-container *ngIf="field.input === 'markdown'">
<span class="code-container">
<code>{{ field.value.value || '-' }}</code>
<code>{{
field.value.translations[displayLanguage]?.value || field.value.value || '-'
}}</code>
</span>
</ng-container>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ import {
SurveysService,
} from '@mzima-client/sdk';
import { TranslateService } from '@ngx-translate/core';
import { untilDestroyed } from '@ngneat/until-destroy';
import { lastValueFrom, Subscription } from 'rxjs';
import { BaseComponent } from '../../base.component';
import { preparingVideoUrl } from '../../core/helpers/validators';
import { dateHelper } from '@helpers';
import { BreakpointService, EventBusService, EventType, SessionService } from '@services';
import { LanguageService } from '../../core/services/language.service';
import { PostTranslateComponent } from '../post-translate/post-translate.component';

@Component({
selector: 'app-post-details',
Expand All @@ -51,6 +54,8 @@ export class PostDetailsComponent extends BaseComponent implements OnChanges, On
public isPostLoading: boolean = true;
public isManagePosts: boolean = false;
public postChanged: boolean;
public displayLanguage: string;

public post: PostResult;
private dataSubscription: Subscription;
constructor(
Expand All @@ -66,6 +71,7 @@ export class PostDetailsComponent extends BaseComponent implements OnChanges, On
private surveyService: SurveysService,
protected sanitizer: DomSanitizer,
private eventBusService: EventBusService,
private languageService: LanguageService,
) {
super(sessionService, breakpointService);
this.getUserData();
Expand All @@ -86,6 +92,7 @@ export class PostDetailsComponent extends BaseComponent implements OnChanges, On
//----------------------
this.allowed_privileges = localStorage.getItem('USH_allowed_privileges') ?? '';
this.postId = Number(params['id']);
this.translatePost();
}
});
if (this.postFromModal) {
Expand All @@ -98,6 +105,16 @@ export class PostDetailsComponent extends BaseComponent implements OnChanges, On
});
}
}
translatePost() {
this.eventBusService
.on(EventType.DisplayTranslatedPost)
.pipe(untilDestroyed(this))
.subscribe({
next: (language) => {
this.displayLanguage = language.code;
},
});
}

loadData(): void {}

Expand Down Expand Up @@ -314,4 +331,27 @@ export class PostDetailsComponent extends BaseComponent implements OnChanges, On
public getDate(value: any, format: string): string {
return dateHelper.getDateWithTz(value, format);
}

public openTranslatePost() {
const dialogRef = this.dialog.open(PostTranslateComponent, {
width: '100%',
maxWidth: '768px',
panelClass: ['modal', 'select-languages-modal'],
data: {
post: this.post,
languages: this.languageService.getEntityLanguages(),
},
});

dialogRef.afterClosed().subscribe((response) => {
if (response) {
this.post = response.post;
this.displayLanguage = response.displayLanguage.code;
}
});
}

public displayOriginalPost() {
this.displayLanguage = '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,12 @@ export class PostEditComponent extends BaseComponent implements OnInit, OnChange
}

async preparationData(): Promise<any> {
for (const task of this.tasks) {
for (const [index, task] of this.tasks.entries()) {
task.fields = await Promise.all(
task.fields.map(
async (field: { key: string | number; input: string; type: string; options: any }) => {
let value: any = {
translations: [],
value: this.form.value[field.key],
};

Expand Down Expand Up @@ -705,8 +706,13 @@ export class PostEditComponent extends BaseComponent implements OnInit, OnChange
this.form.value[field.key]?.map((fieldValue: any) => fieldValue.value) || [];
break;
default:
const postField = this.post.post_content[index].fields.find(
(f: any) => f.key === field.key,
);
value.value = this.form.value[field.key] || null;
value.translations = postField?.value?.translations || [];
}

return {
...field,
value,
Expand All @@ -731,18 +737,19 @@ export class PostEditComponent extends BaseComponent implements OnInit, OnChange
return;
}

const postLanguage = this.selectedLanguage?.code || this.languageService.initialLanguage;
const postData = {
base_language: 'en',
base_language: postLanguage,
completed_stages: this.completeStages,
content: this.description,
description: '',
enabled_languages: {},
form_id: this.formId,
locale: 'en_US',
post_content: this.tasks,
published_to: [],
title: this.title,
type: 'report',
translations: this.post?.translations || [],
};

if (!this.form.valid) this.form.markAllAsTouched();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@
>
<mat-icon icon svgIcon="share" [data-qa]="'share-post'" [attr.post]="post.id"></mat-icon>
</mzima-client-button>
<mzima-client-button
fill="clear"
color="gray"
tabindex="-1"
[iconOnly]="true"
(buttonClick)="openTranslationModal.emit()"
*ngIf="showTranslationsIcon()"
class="post-head__control post-head__control--share"
>
<mat-icon
icon
svgIcon="translate"
[data-qa]="'translate-post'"
[attr.post]="post.id"
></mat-icon>
</mzima-client-button>
<mzima-client-button
*ngIf="!!user?.userId"
fill="clear"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ export class PostHeadComponent extends BaseComponent implements OnInit {
@Input() public editable: boolean;
@Input() public feedView: boolean;
@Input() public deleteable: boolean;
@Input() public hideTranslationsIcon: boolean;
@Output() edit = new EventEmitter();
@Output() refresh = new EventEmitter();
@Output() deleted = new EventEmitter();
@Output() statusChanged = new EventEmitter();
@Output() openTranslationModal = new EventEmitter();
public isLocked: boolean;

constructor(
Expand Down Expand Up @@ -165,4 +167,8 @@ export class PostHeadComponent extends BaseComponent implements OnInit {
duration,
});
}
public showTranslationsIcon() {
const languagesAvailabe = this.post?.enabled_languages?.available?.length > 0;
return !this.hideTranslationsIcon && (languagesAvailabe || this.editable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[deleteable]="post.allowed_privileges.includes('delete')"
(deleted)="deletedHandle()"
(statusChanged)="statusChangedHandle()"
[hideTranslationsIcon]="true"
>
</app-post-head>
</div>
Expand Down
Loading
Loading