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

feat: locales support #156

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions src/date-picker/children/date-table.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, EventEmitter, Input, OnInit, Output, OnChanges, SimpleChanges } from '@angular/core'
import { DateFormat } from '../utils/format'
import { ElLocalesService } from '../../locales';

export type DateRowItem = {
day: number, // day value
Expand Down Expand Up @@ -61,6 +62,11 @@ export class ElDateTable implements OnInit, OnChanges {
return { day: lastCount, monthOffset: -1 }
}).reverse()
}

constructor(
private elLocales: ElLocalesService
) {
}

isToday(item: DateRowItem): boolean {
if (this.currentMonthOffset === null) return false
Expand Down Expand Up @@ -113,6 +119,20 @@ export class ElDateTable implements OnInit, OnChanges {
}

ngOnInit(): void {
this.elLocales.resources$.subscribe(locales => {
const weeks = locales.el.datepicker.weeks;
this.weeks = [
weeks.sun,
weeks.mon,
weeks.tue,
weeks.wed,
weeks.thu,
weeks.fri,
weeks.sat
]
})


this.date = new Date(this.model)
this.getRows()
}
Expand Down
15 changes: 15 additions & 0 deletions src/date-picker/children/month-table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'
import { ElLocalesService } from '../../locales';

@Component({
selector: 'el-month-table',
Expand Down Expand Up @@ -32,6 +33,11 @@ export class EMonthTable implements OnInit, OnChanges {
['五月', '六月', '七月', '八月'],
['九月', '十月', '十一月', '十二月'],
]

constructor(
private elLocales: ElLocalesService
) {
}

clickHandle(i: number, k: number): void {
const monthID = 4 * i + k
Expand All @@ -44,6 +50,15 @@ export class EMonthTable implements OnInit, OnChanges {
}

ngOnInit(): void {
this.elLocales.resources$.subscribe(locales => {
const months = locales.el.datepicker.months;
this.monthRows = [
[ months.jan, months.feb, months.mar, months.apr ],
[ months.may, months.jun, months.jul, months.aug ],
[ months.sep, months.oct, months.nov, months.dec ]
]
})

this.date = new Date(this.model)
this.currentMonth = this.date.getMonth()
}
Expand Down
14 changes: 11 additions & 3 deletions src/date-picker/picker-panel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, EventEmitter, Input, OnChanges, OnInit, Optional, Output, SimpleChanges } from '@angular/core'
import { ElDataPicker } from './picker'
import { ElLocalesService, ElDatePickerLocales } from '../locales'
import { dropAnimation } from '../shared/animation'

export type DateModelItem = {
Expand Down Expand Up @@ -38,16 +39,17 @@ export type DateModelItem = {

<!--year label-->
<span class="el-date-picker__header-label" *ngIf="currentView !== 'year'"
(click)="showPicker('year')">{{dateShowModels.year}} </span>
(click)="showPicker('year')">{{dateShowModels.year}} {{locales.year}}</span>
<!--year range label-->
<span class="el-date-picker__header-label" *ngIf="currentView === 'year'">
{{dateShowModels.yearRange[0]}} - {{dateShowModels.yearRange[1]}}
{{dateShowModels.yearRange[0]}} {{locales.year}} - {{dateShowModels.yearRange[1]}} {{locales.year}}
</span>

<span class="el-date-picker__header-label"
[class.active]="currentView === 'month'"
(click)="showPicker('month')"
*ngIf="currentView === 'date'">{{dateShowModels.month + 1}} 月</span>
*ngIf="currentView === 'date'">{{ locales['month' + (dateShowModels.month + 1)] }}</span>

<button class="el-picker-panel__icon-btn el-date-picker__next-btn el-icon-d-arrow-right"
type="button" (click)="nextYear(1)">
</button>
Expand Down Expand Up @@ -98,8 +100,10 @@ export class ElDatePickerPanel implements OnInit, OnChanges {
showTime: boolean = false
currentView: string = 'date'
dateShowModels: DateModelItem
locales: ElDatePickerLocales

constructor(
private elLocales: ElLocalesService,
@Optional() public root: ElDataPicker,
) {
}
Expand Down Expand Up @@ -160,6 +164,10 @@ export class ElDatePickerPanel implements OnInit, OnChanges {
}

ngOnInit(): void {
this.elLocales.resources$.subscribe(locales => {
this.locales = locales.el.datepicker;
})

// hidden day
this.currentView = this.hiddenDay ? 'month' : 'date'
this.model = this.model || Date.now()
Expand Down
9 changes: 6 additions & 3 deletions src/element-angular.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { ElTableModule } from './table/module'
import { ElContainerModule } from './container/module'
import { ElFormModule } from './form/module'
import { ElTreeModule } from './tree/module'
import { ElLocalesService, ElLocales, ElLocalesModule } from './locales'

export const ElChildModules: any = {
ElButtonsModule, ElIconsModule, ElRadiosModule, ElMenusModule, ElTooltipModule, ElRowModule,
Expand All @@ -47,7 +48,7 @@ export const ElChildModules: any = {
ElSharedModule, ElNotificationModule, ElCascaderModule, ElBadgesModule, ElCardsModule, ElDropdownModule,
ElBreadcrumbsModule, ElDateModule, ElSliderModule, ElDialogModule, ElCarouselModule, ElCollapseModule,
ElAlertModule, ElPaginationModule, ElUploadModule, ElTableModule, ElContainerModule, ElFormModule,
ElTreeModule,
ElTreeModule, ElLocalesModule
}
export const ELMODULES_GROUP: any[] = [
ElButtonsModule, ElIconsModule, ElRadiosModule, ElMenusModule, ElTooltipModule, ElRowModule,
Expand All @@ -56,7 +57,7 @@ export const ELMODULES_GROUP: any[] = [
ElSharedModule, ElNotificationModule, ElCascaderModule, ElBadgesModule, ElCardsModule, ElDropdownModule,
ElBreadcrumbsModule, ElDateModule, ElSliderModule, ElDialogModule, ElCarouselModule, ElCollapseModule,
ElAlertModule, ElPaginationModule, ElUploadModule, ElTableModule, ElContainerModule, ElFormModule,
ElTreeModule,
ElTreeModule, ElLocalesModule
]

@NgModule({
Expand All @@ -70,7 +71,7 @@ export const ELMODULES_GROUP: any[] = [
ElBreadcrumbsModule.forRoot(), ElDateModule.forRoot(), ElSliderModule.forRoot(), ElDialogModule.forRoot(),
ElCarouselModule.forRoot(), ElCollapseModule.forRoot(), ElAlertModule.forRoot(), ElPaginationModule.forRoot(),
ElUploadModule.forRoot(), ElTableModule.forRoot(), ElContainerModule.forRoot(), ElFormModule.forRoot(),
ElTreeModule.forRoot(),
ElTreeModule.forRoot(), ElLocalesModule.forRoot()
],
exports: ELMODULES_GROUP,
})
Expand All @@ -86,6 +87,8 @@ class ElModule {

export {
ElModule,
ElLocales,
ElLocalesService,
ElMessageService,
ElNotificationService,
}
3 changes: 3 additions & 0 deletions src/locales/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './types'
export * from './service'
export * from './module'
116 changes: 116 additions & 0 deletions src/locales/lang/af-ZA.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
export default {
el: {
colorpicker: {
confirm: 'Bevestig',
clear: 'Maak skoon'
},
datepicker: {
now: 'Nou',
today: 'Vandag',
cancel: 'Kanselleer',
clear: 'Maak skoon',
confirm: 'Bevestig',
selectDate: 'Kies datum',
selectTime: 'Kies tyd',
startDate: 'Begindatum',
startTime: 'Begintyd',
endDate: 'Einddatum',
endTime: 'Eindtyd',
prevYear: 'Previous Year', // to be translated
nextYear: 'Next Year', // to be translated
prevMonth: 'Previous Month', // to be translated
nextMonth: 'Next Month', // to be translated
year: 'Jaar',
month1: 'Jan',
month2: 'Feb',
month3: 'Mrt',
month4: 'Apr',
month5: 'Mei',
month6: 'Jun',
month7: 'Jul',
month8: 'Aug',
month9: 'Sep',
month10: 'Okt',
month11: 'Nov',
month12: 'Des',
// week: 'week',
weeks: {
sun: 'So',
mon: 'Ma',
tue: 'Di',
wed: 'Wo',
thu: 'Do',
fri: 'Vr',
sat: 'Sa'
},
months: {
jan: 'Jan',
feb: 'Feb',
mar: 'Mrt',
apr: 'Apr',
may: 'Mei',
jun: 'Jun',
jul: 'Jul',
aug: 'Aug',
sep: 'Sep',
oct: 'Okt',
nov: 'Nov',
dec: 'Des'
}
},
select: {
loading: 'Laai',
noMatch: 'Geen toepaslike data',
noData: 'Geen data',
placeholder: 'Kies'
},
cascader: {
noMatch: 'Geen toepaslike data',
loading: 'Laai',
placeholder: 'Kies',
noData: 'Geen data'
},
pagination: {
goto: 'Gaan na',
pagesize: '/page',
total: 'Totaal {total}',
pageClassifier: ''
},
messagebox: {
title: 'Boodskap',
confirm: 'Bevestig',
cancel: 'Kanselleer',
error: 'Ongeldige invoer'
},
upload: {
deleteTip: 'press delete to remove', // to be translated
delete: 'Verwyder',
preview: 'Voorskou',
continue: 'Gaan voort'
},
table: {
emptyText: 'Geen Data',
confirmFilter: 'Bevestig',
resetFilter: 'Herstel',
clearFilter: 'Alles',
sumText: 'Som'
},
tree: {
emptyText: 'Geen Data'
},
transfer: {
noMatch: 'Geen toepaslike data',
noData: 'Geen data',
titles: ['Lys 1', 'Lys 2'],
filterPlaceholder: 'Voer sleutelwoord in',
noCheckedFormat: '{total} items',
hasCheckedFormat: '{checked}/{total} gekies'
},
image: {
error: 'FAILED' // to be translated
},
pageHeader: {
title: 'Back' // to be translated
}
}
};
Loading