Merge pull request #1983 from dpalou/MOBILE-2808

MOBILE-2808 core: Display month name in ion-datetime
main
Juan Leyva 2019-07-10 17:08:21 +02:00 committed by GitHub
commit ea7caaed20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 5 deletions

View File

@ -73,7 +73,7 @@ export class AddonCalendarEventPage {
});
// Calculate format to use. ion-datetime doesn't support escaping characters ([]), so we remove them.
this.notificationFormat = this.timeUtils.convertPHPToMoment(this.translate.instant('core.strftimedatetimeshort'))
this.notificationFormat = this.timeUtils.convertPHPToMoment(this.translate.instant('core.strftimedatetime'))
.replace(/[\[\]]/g, '');
}
}

View File

@ -43,7 +43,7 @@ export class AddonModDataFieldDateComponent extends AddonModDataFieldPluginCompo
let val;
// Calculate format to use. ion-datetime doesn't support escaping characters ([]), so we remove them.
this.format = this.timeUtils.convertPHPToMoment(this.translate.instant('core.strftimedatefullshort'))
this.format = this.timeUtils.convertPHPToMoment(this.translate.instant('core.strftimedate'))
.replace(/[\[\]]/g, '');
if (this.mode == 'search') {

View File

@ -49,7 +49,7 @@ export class AddonUserProfileFieldDatetimeComponent implements OnInit {
// Calculate format to use. ion-datetime doesn't support escaping characters ([]), so we remove them.
field.format = this.timeUtils.convertPHPToMoment(this.translate.instant('core.' +
(hasTime ? 'strftimedatetimeshort' : 'strftimedatefullshort'))).replace(/[\[\]]/g, '');
(hasTime ? 'strftimedatetime' : 'strftimedate'))).replace(/[\[\]]/g, '');
// Check min value.
if (field.param1) {

View File

@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import * as moment from 'moment';
import { Globalization } from '@ionic-native/globalization';
import { Platform } from 'ionic-angular';
import { Platform, Config } from 'ionic-angular';
import { CoreConfigProvider } from './config';
import { CoreConfigConstants } from '../configconstants';
@ -33,7 +33,7 @@ export class CoreLangProvider {
protected sitePluginsStrings = {}; // Strings defined by site plugins.
constructor(private translate: TranslateService, private configProvider: CoreConfigProvider, platform: Platform,
private globalization: Globalization) {
private globalization: Globalization, private config: Config) {
// Set fallback language and language to use until the app determines the right language to use.
translate.setDefaultLang(this.fallbackLanguage);
translate.use(this.defaultLanguage);
@ -86,6 +86,17 @@ export class CoreLangProvider {
}
}
/**
* Capitalize a string (make the first letter uppercase).
* We cannot use a function from text utils because it would cause a circular dependency.
*
* @param {string} value String to capitalize.
* @return {string} Capitalized string.
*/
protected capitalize(value: string): string {
return value.charAt(0).toUpperCase() + value.slice(1);
}
/**
* Change current language.
*
@ -142,6 +153,13 @@ export class CoreLangProvider {
// Use british english when parent english is loaded.
moment.locale(language == 'en' ? 'en-gb' : language);
// Set data for ion-datetime.
this.config.set('monthNames', moment.months().map(this.capitalize.bind(this)));
this.config.set('monthShortNames', moment.monthsShort().map(this.capitalize.bind(this)));
this.config.set('dayNames', moment.weekdays().map(this.capitalize.bind(this)));
this.config.set('dayShortNames', moment.weekdaysShort().map(this.capitalize.bind(this)));
this.currentLanguage = language;
return Promise.all(promises).finally(() => {