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

Localized date fns #1457

Merged
merged 8 commits into from
Jan 30, 2023
Merged

Localized date fns #1457

merged 8 commits into from
Jan 30, 2023

Conversation

tomazed
Copy link
Contributor

@tomazed tomazed commented Jan 30, 2023

I took a shot at doing localization with date-fns
I do not like the lines

import { de as localeDE, enUS as localeENUS, es as localeES, fr as localeFR, hr as localeHR, it as localeIT, pl as localePL, zhCN as localeZNCN } from 'date-fns/locale'
let locale = {
  de: localeDE,
  enUS: localeENUS,
  es: localeES,
  fr: localeFR,
  hr: localeHR,
  it: localeIT,
  pl: localePL,
  znCN: localeZNCN
}

from https://github.com/advplyr/audiobookshelf/blob/master/client/plugins/init.client.js

but for the love of god, I could not simply do a import locale from 'date-fns/locale' just like stated in the docs
There must be a better way, but this one works...

I also took the liberty to generate the months and weekdays through date-fns format function. I think this render

"WeekdayFri": "Fri",
"WeekdayFriday": "Friday",
"WeekdayMon": "Mon",
"WeekdayMonday": "Monday",
"WeekdaySat": "Sat",
"WeekdaySaturday": "Saturday",
"WeekdaySun": "Sun",
"WeekdaySunday": "Sunday",
"WeekdayThu": "Thu",
"WeekdayThursday": "Thursday",
"WeekdayTue": "Tue",
"WeekdayTuesday": "Tuesday",
"WeekdayWed": "Wed",
"WeekdayWednesday": "Wednesday"

and
"MonthApr": "Apr",
"MonthAug": "Aug",
"MonthDec": "Dec",
"MonthFeb": "Feb",
"MonthJan": "Jan",
"MonthJul": "Jul",
"MonthJun": "Jun",
"MonthMar": "Mar",
"MonthMay": "May",
"MonthNov": "Nov",
"MonthOct": "Oct",
"MonthSep": "Sep",

useless

@tomazed
Copy link
Contributor Author

tomazed commented Jan 30, 2023

having slept on in, just because it works does not mean it should be merged... there are better ways to do it, and I'm not convince putting ConfigDateFnsLocale in the strings was a good choice from a maintainabily point of view....

Let me find a better way

@tomazed
Copy link
Contributor Author

tomazed commented Jan 30, 2023

It's better now, I learnt to use js import 😅
@advplyr hope the code meet project coding guidelines. If you want some other clean up, telle me

client/plugins/i18n.js Outdated Show resolved Hide resolved
@advplyr
Copy link
Owner

advplyr commented Jan 30, 2023

This is great, thanks for taking care of that! Tested and working for all languages.

@advplyr advplyr merged commit e818f27 into advplyr:master Jan 30, 2023
@tomazed tomazed deleted the LocalizedDateFns branch February 13, 2023 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants