hi, moment.locale is working in any other place except the place that I want it to work. I use material date picker and I use a custom date adapter in order to get the desired date from it, here is the adapter:
import { DateAdapter } from '@angular/material'; import * as jalaliMoment from 'jalali-moment'; export const PERSIAN_DATE_FORMATS = { parse: { dateInput: 'jYYYY/jMM/jDD' }, display: { dateInput: 'jYYYY/jMM/jDD', monthYearLabel: 'jMMMM jYYYY', dateA11yLabel: 'jYYYY/jMM/jDD', monthYearA11yLabel: 'jMMMM jYYYY' } }; export class PersianDateAdapter extends DateAdapter<jalaliMoment.Moment> { constructor() { super(); super.setLocale('fa'); } getYear(date: jalaliMoment.Moment): number { return this.clone(date).jYear(); } getMonth(date: jalaliMoment.Moment): number { return this.clone(date).jMonth(); } getDate(date: jalaliMoment.Moment): number { return this.clone(date).jDate(); } getDayOfWeek(date: jalaliMoment.Moment): number { return this.clone(date).day(); } getMonthNames(style: 'long' | 'short' | 'narrow'): string[] { switch (style) { case 'long': case 'short': return jalaliMoment .localeData('fa') .jMonths() .slice(0); case 'narrow': return jalaliMoment .localeData('fa') .jMonthsShort() .slice(0); } } getDateNames(): string[] { const valuesArray = Array<string>(31); let i = 0; let theMax = 19; for (let j = 1777; i < 9; i++ , j++) { valuesArray[i] = String.fromCharCode(j); } for (let x = 1777; x < 1779; x++) { for (let j = 1776 ; i < theMax; i++ , j++) { valuesArray[i] = String.fromCharCode(x, j); } theMax = 29; } valuesArray[i++] = String.fromCharCode(1779, 1776); valuesArray[i] = String.fromCharCode(1779, 1777); return valuesArray; } getDayOfWeekNames(style: 'long' | 'short' | 'narrow'): string[] { switch (style) { case 'long': return jalaliMoment .localeData('fa') .weekdays() .slice(0); case 'short': return jalaliMoment .localeData('fa') .weekdaysShort() .slice(0); case 'narrow': return ['ی', 'د', 'س', 'چ', 'پ', 'ج', 'ش']; } } getYearName(date: jalaliMoment.Moment): string { return this.clone(date) .jYear() .toLocaleString('fa', {useGrouping: false} ); } getFirstDayOfWeek(): number { return jalaliMoment.localeData('fa').firstDayOfWeek(); } getNumDaysInMonth(date: jalaliMoment.Moment): number { return this.clone(date).jDaysInMonth(); } clone(date: jalaliMoment.Moment): jalaliMoment.Moment { return date.clone().locale('fa'); } createDate(year: number, month: number, date: number): jalaliMoment.Moment { if (month < 0 || month > 11) { throw Error( `Invalid month index "${month}". Month index has to be between 0 and 11.` ); } if (date < 1) { throw Error(`Invalid date "${date}". Date has to be greater than 0.`); } const result = jalaliMoment() .jYear(year) .jMonth(month) .jDate(date) .hours(0) .minutes(0) .seconds(0) .milliseconds(0) .locale('fa'); if (this.getMonth(result) !== month) { throw Error(`Invalid date ${date} for month with index ${month}.`); } if (!result.isValid()) { throw Error(`Invalid date "${date}" for month with index "${month}".`); } return result; } today(): jalaliMoment.Moment { return jalaliMoment().locale('fa'); } parse( value: any, parseFormat: string | string[] ): jalaliMoment.Moment | null { if (value && typeof value === 'string') { return jalaliMoment(value, parseFormat, 'fa'); } return value ? jalaliMoment(value).locale('fa') : null; } format(date: jalaliMoment.Moment, displayFormat: string): string { date = this.clone(date); if (!this.isValid(date)) { throw Error('JalaliMomentDateAdapter: Cannot format invalid date.'); } return date.format(displayFormat); } addCalendarYears( date: jalaliMoment.Moment, years: number ): jalaliMoment.Moment { return this.clone(date).add(years, 'jYear'); } addCalendarMonths( date: jalaliMoment.Moment, months: number ): jalaliMoment.Moment { return this.clone(date).add(months, 'jmonth'); } addCalendarDays( date: jalaliMoment.Moment, days: number ): jalaliMoment.Moment { return this.clone(date).add(days, 'jDay'); } toIso8601(date: jalaliMoment.Moment): string { return this.clone(date).format(); } isDateInstance(obj: any): boolean { return jalaliMoment.isMoment(obj); } isValid(date: jalaliMoment.Moment): boolean { return this.clone(date).isValid(); } invalid(): jalaliMoment.Moment { return jalaliMoment.invalid(); } deserialize(value: any): jalaliMoment.Moment | null { let date; if (value instanceof Date) { date = jalaliMoment(value); } if (typeof value === 'string') { if (!value) { return null; } date = jalaliMoment(value).locale('fa'); } if (date && this.isValid(date)) { return date; } return super.deserialize(value); } } and then in app module: providers: [ { provide: MAT_DATE_LOCALE, useValue: 'fa-IR' }, // this statement is doesnt do anything { provide: DateAdapter, useClass: PersianDateAdapter, deps: [ MAT_DATE_LOCALE] }, { provide: MAT_DATE_FORMATS, useValue: PERSIAN_DATE_FORMATS } ], since moment.js is not really helping me here for some god knows reasons I was forced to manually change the numbers to my desired language. the problem is that i don't know how I should change the numbers language in dateInput, dateInput, monthYearLabel, dateA11yLabel, monthYearA11yLabel cause i dont have access to them here. so how can i access dateInput and etc numbers? Thanks in advance -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscr...@googlegroups.com. To post to this group, send email to angular@googlegroups.com. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.