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

Multiple languages: Change i18nId string to i18n object #1548

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
371 changes: 145 additions & 226 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@babel/core": "^7.17.9",
"@babel/preset-env": "^7.16.11",
"@ngtools/webpack": "^16.2.6",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/github": "^8.0.4",
"@types/dom-mediacapture-record": "^1.0.11",
"@types/jasmine": "^4.3.1",
Expand Down Expand Up @@ -168,11 +169,20 @@
"npmPublish": false
}
],
[
"@semantic-release/exec",
{
"prepareCmd": "cd dist; tar -czf en-US.tar.gz en-US"
}
],
[
"@semantic-release/github",
{
"assets": [
{ "path": "dist/en-US/**", "label": "English build" }
{
"path": "dist/en-US.tar.gz",
"label": "English build"
}
]
}
]
Expand Down
2 changes: 2 additions & 0 deletions src/app/teacher/authoring-tool.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ import { ComponentTypeButtonComponent } from '../../assets/wise5/authoringTool/c
import { ComponentInfoDialogComponent } from '../../assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component';
import { ComponentTypeSelectorComponent } from '../../assets/wise5/authoringTool/components/component-type-selector/component-type-selector.component';
import { EditNodeTitleComponent } from '../../assets/wise5/authoringTool/node/edit-node-title/edit-node-title.component';
import { AddComponentButtonComponent } from '../../assets/wise5/authoringTool/node/add-component-button/add-component-button.component';

@NgModule({
declarations: [
AddComponentButtonComponent,
AddLessonChooseLocationComponent,
AddLessonChooseTemplateComponent,
AddLessonConfigureComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<button
mat-icon-button
color="primary"
matTooltip="Add a new component"
i18n-matTooltip
matTooltipPosition="above"
(click)="addComponent()"
>
<mat-icon>add_circle</mat-icon>
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AddComponentButtonComponent } from './add-component-button.component';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { TeacherProjectService } from '../../../services/teacherProjectService';
import { RouterTestingModule } from '@angular/router/testing';
import { MatIconModule } from '@angular/material/icon';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { HarnessLoader } from '@angular/cdk/testing';
import { MatButtonHarness } from '@angular/material/button/testing';
import { ChooseNewComponent } from '../../../../../app/authoring-tool/add-component/choose-new-component/choose-new-component.component';
import { of } from 'rxjs';
import { Node } from '../../../common/Node';

class MockTeacherProjectService {
createComponent() {}
saveProject() {}
}
let loader: HarnessLoader;
describe('AddComponentButtonComponent', () => {
let component: AddComponentButtonComponent;
let fixture: ComponentFixture<AddComponentButtonComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AddComponentButtonComponent],
imports: [MatDialogModule, MatIconModule, RouterTestingModule],
providers: [{ provide: TeacherProjectService, useClass: MockTeacherProjectService }]
});
fixture = TestBed.createComponent(AddComponentButtonComponent);
component = fixture.componentInstance;
component.node = { id: 'node1' } as Node;
loader = TestbedHarnessEnvironment.loader(fixture);
fixture.detectChanges();
});

describe('clicking on the button', () => {
it('shows add component dialog, create selected component, and save project', async () => {
const dialogSpy = spyOn(TestBed.inject(MatDialog), 'open').and.returnValue({
afterClosed: () => of({ action: 'create', componentType: 'OpenResponse' })
} as any);
const projectService = TestBed.inject(TeacherProjectService);
const createComponentSpy = spyOn(projectService, 'createComponent');
const saveProjectSpy = spyOn(projectService, 'saveProject');
await (await loader.getHarness(MatButtonHarness)).click();
expect(dialogSpy).toHaveBeenCalledWith(ChooseNewComponent, {
data: null,
width: '80%'
});
expect(createComponentSpy).toHaveBeenCalled();
expect(saveProjectSpy).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { TeacherProjectService } from '../../../services/teacherProjectService';
import { MatDialog } from '@angular/material/dialog';
import { ChooseNewComponent } from '../../../../../app/authoring-tool/add-component/choose-new-component/choose-new-component.component';
import { filter } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
import { Node } from '../../../common/Node';

@Component({
selector: 'add-component-button',
templateUrl: './add-component-button.component.html'
})
export class AddComponentButtonComponent {
@Input() insertAfterComponentId: string = null;
@Input() node: Node;
@Output() newComponentsEvent: EventEmitter<any> = new EventEmitter<any>();

constructor(
private dialog: MatDialog,
private projectService: TeacherProjectService,
private route: ActivatedRoute,
private router: Router
) {}

protected addComponent(): void {
this.dialog
.open(ChooseNewComponent, {
data: this.insertAfterComponentId,
width: '80%'
})
.afterClosed()
.pipe(filter((componentType) => componentType != null))
.subscribe(({ action, componentType }) => {
if (action === 'import') {
this.router.navigate(['import-component/choose-component'], {
relativeTo: this.route,
state: {
insertAfterComponentId: this.insertAfterComponentId
}
});
} else {
const component = this.projectService.createComponent(
this.node.id,
componentType,
this.insertAfterComponentId
);
this.projectService.saveProject();
this.newComponentsEvent.emit([component]);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@
<mat-icon>close</mat-icon>
</button>
</div>
<ng-template #addComponentButtonTemplate let-componentId="componentId">
<button
mat-icon-button
color="primary"
matTooltip="Add a new component"
i18n-matTooltip
matTooltipPosition="above"
(click)="addComponent(componentId)"
>
<mat-icon>add_circle</mat-icon>
</button>
</ng-template>
<div
*ngIf="!isGroupNode"
class="components-header"
Expand All @@ -57,9 +45,10 @@
fxLayoutGap="4px"
>
<h5 i18n>Components</h5>
<ng-container
*ngTemplateOutlet="addComponentButtonTemplate; context: { componentId: null }"
></ng-container>
<add-component-button
[node]="node"
(newComponentsEvent)="highlightNewComponentsAndThenShowComponentAuthoring($event)"
></add-component-button>
<div *ngIf="isAnyComponentSelected()">
<button
mat-icon-button
Expand Down Expand Up @@ -227,11 +216,12 @@ <h5 i18n>Components</h5>
[componentContent]="component"
></component-authoring-component>
</div>
<div class="add-component">
<ng-container
*ngTemplateOutlet="addComponentButtonTemplate; context: { componentId: component.id }"
></ng-container>
</div>
<add-component-button
class="add-component"
[insertAfterComponentId]="component.id"
[node]="node"
(newComponentsEvent)="highlightNewComponentsAndThenShowComponentAuthoring($event)"
></add-component-button>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { NodeAuthoringComponent } from './node-authoring.component';
import { StudentTeacherCommonServicesModule } from '../../../../../app/student-teacher-common-services.module';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TeacherProjectService } from '../../../services/teacherProjectService';
import { MatDialogModule } from '@angular/material/dialog';
import { TeacherDataService } from '../../../services/teacherDataService';
import { TeacherWebSocketService } from '../../../services/teacherWebSocketService';
import { ClassroomStatusService } from '../../../services/classroomStatusService';
Expand All @@ -24,6 +23,7 @@ import { ActivatedRoute, Router, convertToParamMap } from '@angular/router';
import { of } from 'rxjs';
import { TeacherNodeService } from '../../../services/teacherNodeService';
import { EditNodeTitleComponent } from '../edit-node-title/edit-node-title.component';
import { AddComponentButtonComponent } from '../add-component-button/add-component-button.component';

let component: NodeAuthoringComponent;
let component1: any;
Expand All @@ -39,15 +39,19 @@ let teacherProjectService: TeacherProjectService;
describe('NodeAuthoringComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [EditNodeTitleComponent, NodeAuthoringComponent, TeacherNodeIconComponent],
declarations: [
AddComponentButtonComponent,
EditNodeTitleComponent,
NodeAuthoringComponent,
TeacherNodeIconComponent
],
imports: [
BrowserAnimationsModule,
ComponentAuthoringModule,
DragDropModule,
FormsModule,
HttpClientTestingModule,
MatCheckboxModule,
MatDialogModule,
MatIconModule,
MatInputModule,
PreviewComponentModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Component, Input, OnInit, Signal, WritableSignal, computed, signal } from '@angular/core';
import { Subscription, filter } from 'rxjs';
import { Subscription } from 'rxjs';
import { TeacherDataService } from '../../../services/teacherDataService';
import { TeacherProjectService } from '../../../services/teacherProjectService';
import { ComponentTypeService } from '../../../services/componentTypeService';
import { ComponentServiceLookupService } from '../../../services/componentServiceLookupService';
import { Node } from '../../../common/Node';
import { ComponentContent } from '../../../common/ComponentContent';
import { temporarilyHighlightElement } from '../../../common/dom/dom';
import { MatDialog } from '@angular/material/dialog';
import { ConfigService } from '../../../../wise5/services/configService';
import { ChooseNewComponent } from '../../../../../app/authoring-tool/add-component/choose-new-component/choose-new-component.component';
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { ActivatedRoute, Router } from '@angular/router';
import { TeacherNodeService } from '../../../services/teacherNodeService';
Expand Down Expand Up @@ -37,7 +35,6 @@ export class NodeAuthoringComponent implements OnInit {
private configService: ConfigService,
private componentServiceLookupService: ComponentServiceLookupService,
private componentTypeService: ComponentTypeService,
private dialog: MatDialog,
private nodeService: TeacherNodeService,
private projectService: TeacherProjectService,
private dataService: TeacherDataService,
Expand Down Expand Up @@ -122,34 +119,6 @@ export class NodeAuthoringComponent implements OnInit {
this.scrollToTopOfPage();
}

protected addComponent(insertAfterComponentId: string): void {
const dialogRef = this.dialog.open(ChooseNewComponent, {
data: insertAfterComponentId,
width: '80%'
});
dialogRef
.afterClosed()
.pipe(filter((componentType) => componentType != null))
.subscribe(({ action, componentType }) => {
if (action === 'import') {
this.router.navigate(['import-component/choose-component'], {
relativeTo: this.route,
state: {
insertAfterComponentId: insertAfterComponentId
}
});
} else {
const component = this.projectService.createComponent(
this.nodeId,
componentType,
insertAfterComponentId
);
this.projectService.saveProject();
this.highlightNewComponentsAndThenShowComponentAuthoring([component]);
}
});
}

protected hideAllComponentSaveButtons(): void {
for (const component of this.components) {
const service = this.componentServiceLookupService.getService(component.type);
Expand Down Expand Up @@ -276,7 +245,7 @@ export class NodeAuthoringComponent implements OnInit {
* @param newComponents an array of the new components we have just added
* @param expandComponents expand component(s)' authoring views after highlighting
*/
private highlightNewComponentsAndThenShowComponentAuthoring(
protected highlightNewComponentsAndThenShowComponentAuthoring(
newComponents: any = [],
expandComponents: boolean = true
): void {
Expand Down
12 changes: 7 additions & 5 deletions src/assets/wise5/services/translateProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ export class TranslateProjectService {
}

private getTranslationMappingURL(locale: string): string {
return this.configService.getConfigParam('projectURL').replace('.json', `.${locale}.json`);
return this.configService
.getConfigParam('projectURL')
.replace('project.json', `translations.${locale}.json`);
}

private applyTranslations(projectElement: any, translations: any): void {
Object.keys(projectElement)
.filter((key) => key.endsWith('.i18nId'))
.filter((key) => key.endsWith('.i18n'))
.forEach((key) => {
const translationKey = projectElement[key];
const translationKey = projectElement[key].id;
if (translations[translationKey]) {
const keyWithoutI18NId = key.substring(0, key.lastIndexOf('.i18nId'));
projectElement[keyWithoutI18NId] = translations[translationKey];
const keyWithoutI18NId = key.substring(0, key.lastIndexOf('.i18n'));
projectElement[keyWithoutI18NId] = translations[translationKey].value;
}
});
Object.values(projectElement).forEach((value) => {
Expand Down
Loading