-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(imrove hebrew language): some improvements for hebrew
- Loading branch information
Moshe Vilner
committed
Feb 3, 2019
1 parent
d931b1b
commit d4964fe
Showing
15 changed files
with
151 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/app/examples/notifications/components/notifications.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<div class="container"> | ||
<div class="container" rtl> | ||
|
||
<div class="row"> | ||
<div class="col-12"> | ||
|
4 changes: 2 additions & 2 deletions
4
src/app/examples/stock-market/components/stock-market-container.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Component, DebugElement } from '@angular/core'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { RtlSupportDirective } from './rtl-support.directive'; | ||
import { TranslateModule, TranslateService } from '@ngx-translate/core'; | ||
import { of } from 'rxjs'; | ||
import { cold, getTestScheduler } from 'jasmine-marbles'; | ||
@Component({ | ||
template: ` | ||
<h2 rtl>Something Yellow</h2> | ||
<h2 rtl>The Default (Gray)</h2> | ||
<h2>No Highlight</h2> | ||
<div rtl>Vasili</div>` | ||
}) | ||
class TestComponent {} | ||
|
||
describe('RtlSupportDirective', () => { | ||
let fixture: ComponentFixture<TestComponent>; | ||
let des: DebugElement[]; // the three elements w/ the directive | ||
let bareH2: DebugElement; // the <h2> w/o the directive | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.configureTestingModule({ | ||
imports: [TranslateModule.forRoot()], | ||
declarations: [RtlSupportDirective, TestComponent], | ||
providers: [ | ||
{ | ||
provide: TranslateService, | ||
useValue: { | ||
currentLang: 'he', | ||
onLangChange: cold('--x--y|', { | ||
x: { lang: 'he' }, | ||
y: { lang: 'de' } | ||
}) | ||
} | ||
} | ||
] | ||
}).createComponent(TestComponent); | ||
|
||
getTestScheduler().flush(); // flush the observables | ||
fixture.detectChanges(); // initial binding | ||
|
||
// all elements with an attached RtlDirective | ||
des = fixture.debugElement.queryAll(By.directive(RtlSupportDirective)); | ||
|
||
// the h2 without the RtlDirective | ||
bareH2 = fixture.debugElement.query(By.css('h2:not([rtl])')); | ||
}); | ||
|
||
// color tests | ||
it('should have three rtl styled elements', () => { | ||
expect(des.length).toBe(3); | ||
}); | ||
|
||
it('should set "text-align" rule value to "right" if current language is hebrew', () => { | ||
const textAlign = des[0].nativeElement.style.textAlign; | ||
expect(textAlign).toBe('right'); | ||
}); | ||
|
||
it('should set "direction" rule value to "rtl" if current language is hebrew', () => { | ||
const direction = des[0].nativeElement.style.direction; | ||
expect(direction).toBe('rtl'); | ||
}); | ||
|
||
it('should set "direction" rule value to "ltr" after current language changed to NOT hebrew', () => { | ||
getTestScheduler().flush(); // flush the observables | ||
fixture.detectChanges(); | ||
|
||
const textAlign = des[0].nativeElement.style.textAlign; | ||
expect(textAlign).toBe('left'); | ||
const direction = des[0].nativeElement.style.direction; | ||
expect(direction).toBe('ltr'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Directive, ElementRef, OnInit, OnDestroy } from '@angular/core'; | ||
import { TranslateService, LangChangeEvent } from '@ngx-translate/core'; | ||
import { Subscription } from 'rxjs'; | ||
|
||
@Directive({ | ||
selector: '[rtl]' | ||
}) | ||
export class RtlSupportDirective implements OnInit, OnDestroy { | ||
private subscription: Subscription; | ||
constructor(private el: ElementRef, public translate: TranslateService) { | ||
el.nativeElement.style.textAlign = | ||
translate.currentLang === 'he' ? 'right' : 'left'; | ||
el.nativeElement.style.direction = | ||
translate.currentLang === 'he' ? 'rtl' : 'ltr'; | ||
} | ||
ngOnInit() { | ||
this.subscription = this.translate.onLangChange.subscribe( | ||
(event: LangChangeEvent) => { | ||
this.el.nativeElement.style.textAlign = | ||
event.lang === 'he' ? 'right' : 'left'; | ||
this.el.nativeElement.style.direction = | ||
event.lang === 'he' ? 'rtl' : 'ltr'; | ||
} | ||
); | ||
} | ||
|
||
ngOnDestroy() { | ||
if (this.subscription) { | ||
this.subscription.unsubscribe(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters