onefinestay / react-daterange-picker

Other
563 stars 208 forks source link

i18n fix #119

Closed thaerlabs closed 7 years ago

thaerlabs commented 8 years ago

This will solve both #44 and #116.

The issue is that a the time of the instantiation of WEEKDAYS and MONTHS, lang will be default en..

So now when calling require('moment/locale/ar') somewhere else, the WEEKDAYS and MONTHS will be based on the global moment app locale...

AlanFoster commented 8 years ago

Thanks for the PR!

Would we be able to add tests for this new work too? If you need any help with that, just ping us and we can help get you set up :+1:

thaerlabs commented 8 years ago

@AlanFoster for sure tests have to be added, and I was thinking about adding a page in the demo to demonstrate the locale change, and I think the docs can also be improved

thaerlabs commented 8 years ago

@AlanFoster @rolyatmax I've updated the example, so now we can set locale as a prop #44 . Requiring moment/locale/[whatever] outside won't affect the component. The locale prop will take care of loading locale file, and trigger a re-render as required by @rolyatmax, also the dropdowns of month and year are fine #116.. So last but not least, tests should be added. I think I won't have much time during the week, help is appreciated in this context :dancers:

ghost commented 8 years ago

@AlanFoster could this pr be merged? excited to see the new feature. :+1: :)

AlanFoster commented 8 years ago

Do you feel #56 is enough to implement the new locale support, or does this PR add new functionality that is missing within #56 ?

@miracle2k @rolyatmax @haerlabs As you guys have more context on i18n support i'd love your 2¢ on this

miracle2k commented 8 years ago

The differences between my patch in 56 and this one aren't so big. The require() issue might need to be addressed. I am +0 on the _setupLocale cache.

This PR adds a nice example, and it seems @thaerlabs has more interesting in moving this forward.

AlanFoster commented 8 years ago

Great, thanks for the input @miracle2k :+1:

Getting i18n support would obviously be great to have merged and released; are you happy to do the remaining work for this PR @thaerlabs to help get this PR shipped?

miracle2k commented 8 years ago

Can we get this merged? Seems @thaerlabs made some changes.

AlanFoster commented 8 years ago

@thaerlabs Looks good to me; Would you mind adding some quick tests then we can get this merged in? :)

thaerlabs commented 8 years ago

@AlanFoster I'll work on the tests ASAP. I think also that we should enhance the documentation, especially for the fact that this feature requires the user to require the moment/locale manually, otherwise setting the prop won't be enough to change the datepicker. This approach is better than dynamic require the locale in the _setupLocale function when componentWillReceiveProps, because when webpack bundles, it will put there all the moment/locale/**, as it doesn't know which one to pic.

thaerlabs commented 8 years ago

@AlanFoster can you help me in testing the months dropdown and the weekdays text? I want to assert against the text content of the months and weekdays when changing locale

fluse commented 8 years ago

when will this merged?

evgenTraytyak commented 8 years ago

@AlanFoster ping

AlanFoster commented 8 years ago

@thaerlabs Would love to get this out; What testing difficulties did you have? :+1:

evgenTraytyak commented 8 years ago

@thaerlabs russian locale ru doesn't work :( Uncaught TypeError: Expected Array or iterable object of values: [object Object]

belarusian locale be too..

onzag commented 8 years ago

@thaerlabs is this merged? how can I check this? do you have a bit of documentation? I need to use this in production :+1:

Sorry I'm a bit of a newbie with git I can't find the repo.

maullerz commented 8 years ago

Uncaught TypeError: Expected Array or iterable object of values: [object Object] belarusian locale be too..

its because in moment@2.11.0 they change format of weekdays and months for some locales RU https://github.com/moment/moment/blob/develop/locale/ru.js so its now objects, not arrays

i didn`t found any issue or PR about that, only this commit

fluse commented 8 years ago

@AlanFoster please merge branches!!!!!!!

thaerlabs commented 8 years ago

@AlanFoster I added tests for the month and year headers. Please check it and provide your feedback!

thaerlabs commented 8 years ago

@evgenTraytyak @maullerz the problem is with the locale definition for both ru and be. Somebody should fix the format and open a pull request to moment. I don't think it's a good idea to work around this bug in moment in the datepicker component, as if they fix it, it'll break again the datepicker. Plus we should add a special case for those locales with a different format, which will make the component more fragile. that's my thought..

maullerz commented 8 years ago

nvm, see @wmertens comment

ashmigelski commented 8 years ago

Guys, you cant merge with ru locale issue. And more over there's no bug in moment.js...

Here's my workaround, just add isArray check for lang._weekdays and lang._months in https://github.com/onefinestay/react-daterange-picker/blob/master/src/calendar/CalendarMonth.jsx#L12

    const lang = moment().localeData();

    let weekdays = lang._weekdays;
    if (!Array.isArray(weekdays)) {
        weekdays = weekdays.standalone;
    }
    let months = lang._months;
    if (!Array.isArray(months)) {
        months = months.standalone;
    }

    const WEEKDAYS = Immutable.List(weekdays).zip(Immutable.List(lang._weekdaysShort));
    const MONTHS = Immutable.List(months);
maullerz commented 8 years ago

Guys, you cant merge with ru locale issue. And more over there's no bug in moment.js...

why? can you explain?

ashmigelski commented 8 years ago

why? can you explain?

I explained it 3 month ago https://github.com/onefinestay/react-daterange-picker/pull/119#discussion_r56464224

In short

If you want datepicker work well with all locations, you have to add check is locale is simple (_monthNames just array) or complex (_monthNames is an object and real month names can be found inside, like _monthNames['standalone'] )

Code in my prev comment

wmertens commented 8 years ago

Moment has an API to get the months and weekdays as an array. Call that instead of relying on Moment internals: http://momentjs.com/docs/#/i18n/listing-months-weekdays/

thaerlabs commented 8 years ago

@wmertens great hint! I'll fix that ASAP

AlanFoster commented 8 years ago

@thaerlabs Let me know when you've had the time to apply the PR feedback from @wmertens After a squash of commits I'll try to get this in! :+1:

AlanFoster commented 8 years ago

@thaerlabs Requires a rebase :) Let me know if I can do anything to help out :+1:

maullerz commented 7 years ago

@thaerlabs any news about that? :pray:

andywer commented 7 years ago

@AlanFoster @thaerlabs Is there anything left to do? We also stumbled upon the localization issue here.

maullerz commented 7 years ago

@andywer fyi there is rebased and fixed PR forked from this - #150 so in my project i use react-daterange-picker from this branch - https://github.com/maullerz/react-daterange-picker.git#dist Temp workaround while we all waiting updates of original repo.

AlanFoster commented 7 years ago

Closing this in favour of #150

Thanks for the hard work guys; I'll aim to release this as 2.x