-
Notifications
You must be signed in to change notification settings - Fork 124
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
Custom Formats Are Not Working #128
Comments
HI @scarrick68, if that helps, we did it by passing the format like this: local_time(@date_time, :time_with_tz) and specifying the format in our en:
time:
formats:
time_with_tz: "%H:%Mh %Z" |
Ah I see what happened. Sorry this is confusing, but rails helpers (like See line 55 here: local_time/app/helpers/local_time_helper.rb Lines 45 to 57 in 7b60d1d
Changing this is not trivial. Perhaps the action item here is adding a note to the readme saying that default values shouldn't be changed as it won't behave as one might expect. I'll look into it. |
Actually, I'm going to reopen so we remember to document this somehow |
Done in 6294194 For the time being, I'd only recommend using the i18n configuration after understanding which helpers use our Lines 2 to 3 in 7013aa9
"default" is admittedly a confusing choice of name here. Might revisit later. |
@josefarias jose, i really confuse of this config if we leave it(just pure copy-paste), the translation works, but if we change neither in rails views or the js it will revert to english again even we set the i18n in Indonesian <%= local_time(submitted_at, "%a, %d %b %Y ~ %H:%M %Z") %> LocalTime.config.i18n["id"] = {
date: {
dayNames: ["Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"],
abbrdayNames: ["Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"],
monthNames: ["Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "Nopember", "Desember"],
abbrmonthNames: ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nop", "Des"],
yesterday: "kemarin",
today: "hari ini",
tomorrow: "besok",
on: "pada {date}",
formats: {
default: "%b %e, %Y",
thisYear: "%b %e",
}
},
time: {
am: "",
pm: "",
singular: "{time}",
singularAn: "{time}",
elapsed: "{time} lalu",
second: "detik",
seconds: "detik",
minute: "menit",
minutes: "menit",
hour: "hari",
hours: "hari",
formats: {
default: "%l:%M%P",
default_24h: "%H:%M %Z"
}
},
datetime: {
at: "{date} pada {time}",
formats: {
default: "%B %e, %Y pada %l:%M%P %Z",
default_24h: "%B %e, %Y pada %H:%M %Z"
}
}
}
LocalTime.config.locale = "id"
LocalTime.config.useFormat24 = true |
@kwhandy sorry you're finding this confusing! If I understand correctly, the example you shared is working correctly. That makes sense, it looks correct to me! But if you change it, then it stops working. Can I see an example where it stopped working? What did you change exactly? |
@josefarias hi jose, some quick update, this finally works turns out, it's about library import ordering issue this is what it should: import "@hotwired/turbo-rails"
import LocalTime from "local-time"
import * as ActiveStorage from "@rails/activestorage"
import morphdom from "morphdom"
import "./controllers" and this what i did: import "@hotwired/turbo-rails"
import * as ActiveStorage from "@rails/activestorage" // this dude should below local-time when we import it
import LocalTime from "local-time"
import morphdom from "morphdom"
import "./controllers" for some reason, activestorage block local-time to translate the object which make me confused for days to figure out WHY, even think switch to luxon lol but glad it wouldn't happen in near future(at least) :D |
I am trying to set a default DateTime format for my app, so I did this in a JS file and included it into my application.js
I printed in the console and see the updated default format, but all of my DateTimes still show in the original default format. I am only interested in DateTime. I set the default on all of them just in case I was passing an unexpected type.
I called local_time in the view like this with :my_format being added to the formats instead of overriding default:
The text was updated successfully, but these errors were encountered: