Locales
Day.js ships a file for each locale. yuga builds a locale out of Intl the first time it’s used, from any BCP 47 language tag, so there is nothing to import:
yuga("2024-05-15").locale("fr").format("dddd D MMMM"); // "mercredi 15 mai"yuga("2024-05-15").locale("ru").format("D MMMM"); // "15 мая", the form used in a dateyuga("2024-05-15").locale("he").format("dddd"); // "יום רביעי"A locale gives:
- the month and weekday names, long, short and minimal;
- the meridiem (
AM/PM); - the first day of the week, from
Intl.Locale#getWeekInfo(see Requirements); - the first week of the year.
The global locale
Section titled “The global locale”yuga.locale(name) sets the locale of every new instance and returns its name. instance.locale(name) returns a copy in another locale.
yuga.locale("de");yuga("2024-05-15").format("dddd"); // "Mittwoch"yuga.locale("en");Your own locale
Section titled “Your own locale”Register a locale object under a name. With its own weekStart it doesn’t need getWeekInfo.
yuga.locale("en-work", { name: "en-work", months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], weekdays: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], weekStart: 1, // Monday. ordinal: (n) => `${n}.`,});
yuga("2024-05-15").startOf("week").format("dddd Do"); // "Monday 13."Localized formats
Section titled “Localized formats”L, LL, LT and the other localized templates come with the localized-format extension, built from Intl:
import { localizedFormat } from "yugajs/extension/localized-format";
yuga.extend(localizedFormat);
yuga("2024-05-15").locale("de").format("LL"); // "15. Mai 2024"yuga("2024-05-15").locale("ja").format("LL"); // "2024年5月15日"Differences from Day.js’s locale files
Section titled “Differences from Day.js’s locale files”Names come from Intl, so in a few locales they differ from Day.js’s hand-written files: a different abbreviation, or a capital letter. The Day.js parity document lists every one tested.