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

Provide a way to switch back to default (en) locale #2687

Closed
2 tasks done
m-gallesio opened this issue Oct 5, 2022 · 8 comments
Closed
2 tasks done

Provide a way to switch back to default (en) locale #2687

m-gallesio opened this issue Oct 5, 2022 · 8 comments

Comments

@m-gallesio
Copy link
Contributor

Prerequisites

Proposal

I think there should be a way to explicitly set the locale of a single picker to the library default (en / en-US), which does not seem possible at the moment.

Motivation and context

This is relevant in the following cases:

  • the global locale is overridden
  • there is a desire to keep the code "culture-neutral", so the locale is explicitly set every time
@Eonasdan
Copy link
Owner

I don't follow. The locale can be set per picker or globally and the updateOptions would give you the ability to change it whenever you needed.

@m-gallesio
Copy link
Contributor Author

Take this code:

import { TempusDominus, loadLocale, locale } from '@eonasdan/tempus-dominus';
import { localization, name } from "@eonasdan/tempus-dominus/dist/locales/it";
loadLocale({localization, name});
locale('it');

const td = new TempusDominus(document.getElementById('datetimepicker1'));

Now that the global locale is it, there does not seem to be an immediate way to set a single picker to specifically an en/en-us locale.
This also conceptually happens if the browser's current locale is something other than en/en-us (it starts with a language other than English).

@Eonasdan
Copy link
Owner

Can do td = new TempusDominus(document.getElementById('datetimepicker1'), { localization: { locale: 'en' }})

@m-gallesio
Copy link
Contributor Author

That does change the displayed language in the main picker (which I assume uses Intl) but not the tooltips and some other options (e.g. first day of the week).

@Eonasdan
Copy link
Owner

OOH. I see. Since you said locale, I thought you where talking about localization.locale not the localization object itself.

Right so setting it globally replaces the defaultoptions and thus there is no way to revert that. Hmm. I could create an en-Us locale file that could be loaded. That seems heavy though.

HeavyGIF

@m-gallesio
Copy link
Contributor Author

Update, I tried doing this at startup (no global TD locale, browser in it locale):

loadLocale({ localization: DefaultOptions.localization, name: "en-us" });

which partially works since it sets tooltips and day of week, but not those parts which depend on Intl:

immagine

I also anticipate the need of an en-gb locale due to differing date formats, unless it can be somehow managed with Intl.

@mvxproject
Copy link

mvxproject commented Nov 3, 2022

To set locale globally to English:

tempusDominus.DefaultOptions.localization.locale = 'en';

To test:

Open DevTools in Chrome -> Open the Console drawer. Click on the three-dotted menu -> Click on More tools -> Sensors. From the Sensors tab, set the location according to your preference.

Before:

before

after setting : tempusDominus.DefaultOptions.localization.locale = 'en';

after

I have to mention one problem with localization when using CustomDateFormat plugin:

the English format is always used even in cultures like 'fr'

fr

@Eonasdan Eonasdan moved this from 🆕 New to 🔖 Ready in Tempus Dominus Jan 17, 2023
@Eonasdan Eonasdan moved this from 🔖 Ready to 🏗 In progress in Tempus Dominus Apr 20, 2023
Eonasdan added a commit that referenced this issue Apr 21, 2023
@Eonasdan Eonasdan mentioned this issue Apr 21, 2023
Eonasdan added a commit that referenced this issue Apr 21, 2023
* fixes #2795
* fixes #2784
* fixes #2687
* fixes #2786
* resolves #2764 
* fix repl cdn links
* fix date range bug
Eonasdan added a commit that referenced this issue Apr 22, 2023
* fixes #2795
* fixes #2784
* fixes #2687
* fixes #2786
* resolves #2764 
* fix repl cdn links
* fix date range bug
@Eonasdan Eonasdan moved this from 🏗 In progress to 👀 In review in Tempus Dominus Apr 22, 2023
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Tempus Dominus Apr 22, 2023
@Eonasdan
Copy link
Owner

Hello 6.7.7 should resolve this. There's an additional export DefaultEnLocalization that provides the default en-US locale options

@Eonasdan Eonasdan moved this from ✅ Done to 🚀 Released in Tempus Dominus Apr 22, 2023
Eonasdan added a commit that referenced this issue May 22, 2023
* Fix #2788 (#2790)

Break if current range-start is clicked to prevent infinite loop

* adding placement option (#2789)

* fixes #2785 (#2797)

* fixes #2785
fixes #2783
fixes #2768
improves docs flow

* fixed plugin/locale missing type defs

* 2791 more tests (#2800)

* validation tests
* update datetime tests
* "dates" tests
* actions tests

* fixing infinity loop bug in date range (#2798)

* Improvements (#2801)

* fixes #2795
* fixes #2784
* fixes #2687
* fixes #2786
* resolves #2764
* fix repl cdn links
* fix date range bug

* version 6.7.7

* version 6.7.7

---------

Co-authored-by: iTzVirtual_ <[email protected]>
Co-authored-by: Killian Hale <[email protected]>
Co-authored-by: GitHub User <[email protected]>
Eonasdan added a commit that referenced this issue Jul 3, 2023
* Fix #2788 (#2790)

Break if current range-start is clicked to prevent infinite loop

* adding placement option (#2789)

* fixes #2785 (#2797)

* fixes #2785
fixes #2783
fixes #2768
improves docs flow

* fixed plugin/locale missing type defs

* 2791 more tests (#2800)

* validation tests
* update datetime tests
* "dates" tests
* actions tests

* fixing infinity loop bug in date range (#2798)

* Improvements (#2801)

* fixes #2795
* fixes #2784
* fixes #2687
* fixes #2786
* resolves #2764
* fix repl cdn links
* fix date range bug

* version 6.7.7

* version 6.7.7

---------

Co-authored-by: iTzVirtual_ <[email protected]>
Co-authored-by: Killian Hale <[email protected]>
Co-authored-by: GitHub User <[email protected]>
Eonasdan added a commit that referenced this issue Jul 3, 2023
* fixes #2795
* fixes #2784
* fixes #2687
* fixes #2786
* resolves #2764 
* fix repl cdn links
* fix date range bug
Eonasdan added a commit that referenced this issue Jul 3, 2023
* fixes #2795
* fixes #2784
* fixes #2687
* fixes #2786
* resolves #2764 
* fix repl cdn links
* fix date range bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants