-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Use Option to avoid failures in locale_match! #7
Conversation
It seems to be a reasonable fix with the less problem so I like the solution! |
Small issue with the CI, you need to add the changes of the generated file to the PR. |
ed1b3a5
to
7adaa9a
Compare
🤦 just pushed an update! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks much cleaner I love it! 👌
It would be super nice if we can get a review of @CfirTsabari on this. At least at a conceptual level. I think the idea makes a lot of sense (imo). Maybe an additional review from someone at chrono would be very useful too.
All in all it's perfect and I will merge if I don't receive more feedbacks.
Thanks, I see that some tests are failing, will try to fix that ASAP (and add a few more just to make sure what I fixed doesn't break 🙂 ) Yeah it would be great if we could get more eyes on this. For the record I tested this as a patch with |
Just for my own curiosity. Do you use that in chrono or you have a different project that (will) use pure-rust-locales? |
I'm working on a project where I need to format monetary and decimal values in users' locales properly and to my surprise there was no crate already available to format decimal numbers like this, so we had to implement everything from scratch. Thankfully |
I think you can always call the libc to get some localized formatting. Same for the datetime formatting/translation actually. The only perk of using pure-rust-locales is because it's consistent across OS (and libc). |
I made this crate for date and time formatting: https://crates.io/crates/libc-strftime But I think it's pretty similar for monetary and decimal separator and such |
7adaa9a
to
380a79b
Compare
Thanks for the advice, will check out the links! Yeah we might be able to make do by using the native functions since it's a server-side app that will only ever be running on Linux, the only question is how well is it supported on dev machines which may run any other OS. But we don't really need to support any advanced formatting, just being able to set correct number of decimal places, decimal, and thousands separators properly will most likely be enough. Just pushed a new commit that should fix the broken tests and add a couple of more tests for |
Oh it's complaining about the source code, not about the generated code... just pushed a fix. |
This change adds postprocessing of parsed constants to determine if values are present in all locales (optional), or ensures that the types are always the same. For example, if a value was previously registerd as `i64` for one locale _and_ a `String` for another, it will now always be a `Sttring, it will now always be a `String`. Similarly, when certain values are present in some locales but not others, the types will be wrapped in `Option`. When a whole module is missing, a dummy one will be created with all `const`s set to `None`. All of this should fix the compilation errors when trying to use `locale_match!` with locales that previously had diverging types. This is most likely _not_ a backwards compatible change, still I'm going to double check that nothing breaks in `chrono`. Closes chronotope#4.
380a79b
to
d41f1b6
Compare
@pitdicker 👋 according to git blame it seems you wrote most of the code in I guess we should be pretty safe anyway since it's hidden under the |
Yeah don't worry there are quite some heavy tests there https://github.com/cecton/chrono/blob/main/src/format/strftime.rs#L620 |
I mostly moved around your code 😄. But I am happy to. As far as I can tell the constants used by chrono are unchanged with this PR, because they were available for all locales already. Cool to have constants such as |
Tests with chrono pass with this branch. |
Awesome, thanks for the speedy response! 🍻 |
@cecton do you think this could be merged now as is, or do you think we need to do further testing? |
Yes sure! I was hoping to get more feedback but that is fine. Will do asap |
Released 0.7.0 |
Thanks, I really appreciate it! |
This change adds postprocessing of parsed constants to determine if values are present in all locales (optional), or ensures that the types are always the same. For example, if a value was previously registerd as
i64
for one locale and aString
for another, it will now always be aString
.Similarly, when certain values are present in some locales but not others, the types will be wrapped in
Option
.When a whole module is missing, a dummy one will be created with all
const
s set toNone
.All of this should fix the compilation errors when trying to use
locale_match!
with locales that previously had diverging types.This is most likely not a backwards compatible change, still, I'm going to double check that nothing breaks in
chrono
.Closes #4.