Skip to content

Instantly share code, notes, and snippets.

@edisdev
Last active May 11, 2021 10:37
Show Gist options
  • Save edisdev/b67597b55c5edd3dd12527e55b43f7dc to your computer and use it in GitHub Desktop.
Save edisdev/b67597b55c5edd3dd12527e55b43f7dc to your computer and use it in GitHub Desktop.
Ay ve Günlerin Javascript İle Dil Ayarı İçin Ufak Bir Yöntem
function calendarTranslation(lang) {
const currentYear = new Date().getFullYear()
const months = Array.from({length: 12}, function(_, index) {
let name = new Date(currentYear, index).toLocaleString(lang, { month: 'long' })
return ({index, name })
})
const days = Array.from({length: 7}, function (_, index) {
let name = new Date(currentYear, '00', index).toLocaleString(lang, { weekday: 'long' })
let order = new Date(currentYear, '00', index).getDay()
return ({ name, order })
})
return {
months,
days
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment