Translate weekdays and months with "Intl", which is included by your browser. It is a really minimal approach.


npm i @dipser/wmlang.js


<script type="module"> import { weekday, month } from './index.js'; console.log( weekday(1, 'de') ); // => Montag </script>


How it works

Since browsers have implemented Intl, they have language support date output. See caniuse.com/Intl. To use weekdays and months names for different things, we just need to select a Intl date and get the format of a weekday or month.

function month(month, locale = 'en') { let intl = new Intl.DateTimeFormat(locale, { month: 'long' }); return intl.format( new Date(1970, Number(month) - 1, 1) ); } month(2, 'de'); // => Februar