question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Localizing labels and messages is not working

See original GitHub issue

Hi and thx for the library update =)

Here my code :

import { OwlDateTimeModule, OwlMomentDateTimeModule, OWL_DATE_TIME_FORMATS, OwlDateTimeIntl } from '@danielmoncada/angular-datetime-picker';
...
export class DefaultIntl extends OwlDateTimeIntl {
  upSecondLabel = 'Add a second';
  downSecondLabel = 'Minus a second';
  upMinuteLabel = 'Add a minute';
  downMinuteLabel = 'Minus a minute';
  upHourLabel = 'Add a hour';
  downHourLabel = 'Minus a hour';
  prevMonthLabel = 'Previous month';
  nextMonthLabel = 'Next month';
  prevYearLabel = 'Previous year';
  nextYearLabel = 'Next year';
  prevMultiYearLabel = 'Previous 21 years';
  nextMultiYearLabel = 'Next 21 years';
  switchToMonthViewLabel = 'Change to month view';
  switchToMultiYearViewLabel = 'Choose month and year';
  cancelBtnLabel = 'Annuler';
  setBtnLabel = 'Valider';
  rangeFromLabel = 'From';
  rangeToLabel = 'To';
  hour12AMLabel = 'AM';
  hour12PMLabel = 'PM';
}
...
  providers: [
        { provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
        { provide: LOCALE_ID, useValue: 'fr' },
        { provide: MAT_DATE_FORMATS, useValue: MY_FORMATS },
        { provide: MAT_DATE_LOCALE, useValue: 'fr-FR' },
        { provide: OWL_DATE_TIME_FORMATS, useValue: DATETIME_FORMATS },
        { provide: OwlDateTimeIntl, useClass: DefaultIntl }
      ]

I’ve customized setBtnLabel and cancelBtnLabel, but labels are not replaced and I still see “Cancel” and “Set”

I use @danielmoncada/angular-datetime-picker@9.4.2, @angular/core@~9.1.7 and build with Ivy.

I’ve tried in the demo stackblitz and this is working but those demo use an old version of the lib. I tried to make my own stackblitz with updated versions but it seems it doesn’t work with your lib : https://stackblitz.com/edit/angular-ivy-h2trhq?file=src%2Fapp%2Fapp.component.html

What should I do? Thx

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
StalinMazaEpncommented, Sep 7, 2020

I used this code to set language “es” and it worked, I hope it helps you

datetime-picker.config.ts

import { OwlDateTimeIntl } from '@danielmoncada/angular-datetime-picker';
import { Injectable } from '@angular/core';

@Injectable()
export class DefaultIntl extends OwlDateTimeIntl {
    /** A label for the up second button (used by screen readers).  */
    upSecondLabel = 'Añadir un segundo';

    /** A label for the down second button (used by screen readers).  */
    downSecondLabel = 'Restar un segundo';

    /** A label for the up minute button (used by screen readers).  */
    upMinuteLabel = 'Añadir un minuto';

    /** A label for the down minute button (used by screen readers).  */
    downMinuteLabel = 'Menos de un minuto';

    /** A label for the up hour button (used by screen readers).  */
    upHourLabel = 'Añadir una hora';

    /** A label for the down hour button (used by screen readers).  */
    downHourLabel= 'Menos de una hora';

    /** A label for the previous month button (used by screen readers). */
    prevMonthLabel= 'Mes pasado';

    /** A label for the next month button (used by screen readers). */
    nextMonthLabel= 'Mes siguiente';

    /** A label for the previous year button (used by screen readers). */
    prevYearLabel = 'Año pasado';
    /** A label for the next year button (used by screen readers). */
    nextYearLabel = 'Año siguiente';

    /** A label for the previous multi-year button (used by screen readers). */
    prevMultiYearLabel = 'Hace 21 años';

    /** A label for the next multi-year button (used by screen readers). */
    nextMultiYearLabel = 'En los proximos 21 años';

    /** A label for the 'switch to month view' button (used by screen readers). */
    switchToMonthViewLabel = 'Cambiar a la vista de mes';

    /** A label for the 'switch to year view' button (used by screen readers). */
    switchToMultiYearViewLabel = 'Escoger mes y año';

    /** A label for the cancel button */
    cancelBtnLabel = 'Cancelar';

    /** A label for the set button */
    setBtnLabel = 'Guardar';

    /** A label for the range 'from' in picker info */
    rangeFromLabel = 'Desde';

    /** A label for the range 'to' in picker info */
    rangeToLabel = 'Hasta';

    /** A label for the hour12 button (AM) */
    hour12AMLabel = 'AM';

    /** A label for the hour12 button (PM) */
    hour12PMLabel = 'PM';
};

y en el app.module.ts lo importe de la siguiente manera

import { registerLocaleData } from '@angular/common';
import { OwlDateTimeModule, OwlNativeDateTimeModule, OWL_DATE_TIME_LOCALE, OwlDateTimeIntl } from '@danielmoncada/angular-datetime-picker';

registerLocaleData(localeEs, 'es');


imports: [
        OwlDateTimeModule,
        OwlNativeDateTimeModule,
],
providers: [
        {
            provide: OwlDateTimeIntl,
            useClass: DefaultIntl
        },
        {
            provide: OWL_DATE_TIME_LOCALE,
            useValue: 'es'
        },
]
1reaction
barden42commented, Aug 13, 2020

Hi,

I have the same issue, impossible to translate buttons “cancel” and “set”. I tried both solutions, this one of the documentation and the code posted by @Lempkin

What is the solution ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Localization labels & messages not working #405 - GitHub
Hi Daniel, I'm trying to use the localization & messages like in your example / docs here, but it doesn't seem to work:...
Read more >
Localizing Labels and Error Messages
Labels and error messages are the static text that make up the Data Director user interface. The text cannot be localized through the...
Read more >
Launchscreen ignoring my localizat… | Apple Developer Forums
It ignores completely my localization in Pt-Br. I have just a label on it with a loading message. I've tried both strings and...
Read more >
Angular Owl Date Time Picker Labels and Buttons not localized
In your case the labels and messages seem to be not localized - try the approach in my answer below and adjust the...
Read more >
Localization of AIP Client - cannot find --> Label: "not set"
I cannot find The phrase "not set", I scanned through the xml files without success, even policy exports did not show any sign...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found