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

Arabic locale for Calendar #351

Closed
AlexIach opened this issue Mar 23, 2017 · 18 comments
Closed

Arabic locale for Calendar #351

AlexIach opened this issue Mar 23, 2017 · 18 comments

Comments

@AlexIach
Copy link

Wrong displaying Calendar using Arabic locale.
In Arabic calendar first day of the week is Saturday, so it causes misalignment between Day Of Week's name and date. So I can make offset for day of week, to adjust it to date, but it will not be properly. Is is possible to make offset for date as I can do for day of weeks?

@edenman
Copy link
Collaborator

edenman commented Mar 23, 2017

@AlexIach we should be respecting the "first day of the week" setting on the locale. Can you tell me exactly which language+country your locale is set to?

@AlexIach
Copy link
Author

@edenman Language Arabic, Country United Arab Emirates. To create Calendar I write:
Calendar today = Calendar.getInstance(getLocale());
Where in method getLocale() I get current System locale.
Calendar with Arabic locale is displayed as Calendar with USA locale. To adjust to common Arabic calendars need to make a 1 day offset. I think so.
I attached the screen with common Arabic calendar (1st screen) and USA calendar (2nd screen). And for example look at May.
Regards,
Alex.

hijri-calendar-2017-islamic-calendar-2017-2017-calendar-images-zwqrug-quhqwb
usa calendar

@edenman
Copy link
Collaborator

edenman commented Mar 24, 2017

screenshot_20170324-095140
this is what the calendar looks like for March 2017 in arabic+UAE locale (created using new Locale("ar", "AE") so I didn't have to futz with my phone settings). It seems to be doing the right thing: first row right-to-left is Feb 25 (Saturday)-28, then Mar 1-3(Friday).

Can you show me a screenshot of CalendarPickerView on your phone? Maybe the locale isn't set up the same way?

@AlexIach
Copy link
Author

I don't know Arabic language, but using dictionary and Google Translate, your header is populated with the following way (Left to right) Sunday, Saturday, Friday, Thursday, Wednesday, Tuesday, Monday. On your CalendarPickerView 20th of March ( Numerical 20th in Arabic is " ٢٠" ) is Wednesday( الأربعاء ) but in fact it's Monday.

@AlexIach
Copy link
Author

I have the same problem in my CalendarPickerView 20th March is also displayed in wrong place. But header with day of weeks is displayed in a proper way as in my screen with common Arabic Calendar ( Left to Right ) Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday.
screen shot 2017-03-24 at 9 59 39 pm

@AlexIach
Copy link
Author

I also created using Locale locale = new Locale("ar", "AE");

@AlexIach
Copy link
Author

Hello @edenman Ohhh sorry man, I'm confused because of Android devices and Emulators, in one device everything is displayed properly ( right to left as expected ) in others no. I can not find reason why? It does not depends on devices' model and Android version. I have no idea why so stare behavior when locale is Arabic.

@eslamwael74
Copy link

hello @AlexIach how to set days in week start from السبت

@edenman
Copy link
Collaborator

edenman commented Sep 13, 2017

@eslamwael74 this library should be respecting the user's locale's setting for the "first day of the week". If you're not seeing this work correctly, please comment here with:

  • Device name
  • Device OS version
  • Locale string
  • A screenshot

@eslamwael74
Copy link

eslamwael74 commented Sep 13, 2017

-Device Name : Honor8 and nexux 5X
-Device OS version: 7.0N , 6.0M
-Locale String: calendarView.init(today,nextYear.getTime(),new Locale("ar","EG")). inMode(CalendarPickerView.SelectionMode.MULTIPLE);
-Screen shoot: and when select to any day say to me this toast
screenshot_1505323042

Very Thanks for your support. @edenman

@eslamwael74
Copy link

I am waiting for your response @edenman

@edenman
Copy link
Collaborator

edenman commented Sep 14, 2017

As I stated earlier in this thread, we rely on Calendar.getFirstDayOfWeek to determine the ordering of days within a week. For new Locale("ar","EG"), getFirstDayOfWeek() returns 7 (Sunday, or الأحد). So that's why الأحد is the right-most day of the week in the screenshot you posted.

If you want to change the first day of the week for a given Locale, you can do this:

        Calendar cal = Calendar.getInstance(TimeZone.getDefault(), new Locale("ar", "EG"));
        cal.setFirstDayOfWeek(Calendar.FRIDAY);

...before you initialize the CalendarPickerView.

@edenman edenman closed this as completed Sep 14, 2017
@eslamwael74
Copy link

eslamwael74 commented Sep 14, 2017

Not Working :D
Calendar c = Calendar.getInstance(TimeZone.getDefault(), new Locale("ar", "EG")); c.setFirstDayOfWeek(Calendar.SATURDAY); calendarView.init(today, nextYear.getTime()). inMode(CalendarPickerView.SelectionMode.MULTIPLE);

please solve this issue!! @edenman

@JakeWharton
Copy link
Member

JakeWharton commented Sep 14, 2017 via email

@eslamwael74
Copy link

eslamwael74 commented Sep 14, 2017

for Eric's time, i solved it :D
replace this function `
private static int getDayOfWeek(int firstDayOfWeek, int offset, boolean isRtl) {

        dayOfWeek = firstDayOfWeek + offset;
    }
        if (isRtl) {
            return 8 - dayOfWeek;
        }
    return dayOfWeek;
}  `  to this function for save Eric's @edenman  Time.

` private static int getDayOfWeek(int firstDayOfWeek, int offset, boolean isRtl) {
int dayOfWeek;

    if(Locale.getDefault().getLanguage() == "en"){
        dayOfWeek = firstDayOfWeek + offset;
    }else{
        dayOfWeek = Calendar.SUNDAY + offset+1;
        if (isRtl) {
            return 8 - dayOfWeek;
        }
    }

    return dayOfWeek;
}  `

Thank you for support. @JakeWharton @edenman

@arvi
Copy link

arvi commented Oct 19, 2017

Hello. I was able to translate the calendar to Arabic, however, I want to retain the year and days as english / latin instead of Arabic. I was able to create a workaround for Lollipop and up however, cannot find a workaround for JellyBean and KitKat.

Is there a way to specifically initialize the days and year from arabic to english numbers? Thanks a lot.

        if (MyApp.getInstance().selectedLang.equals("en")) {
            calendarPickerInitializer = calendarPickerView.init(today, nextYear.getTime());
        } else {
            if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                // using english numbers instead of arabic
                calendarPickerInitializer = calendarPickerView.init(today, nextYear.getTime(), new Locale.Builder().setLanguageTag("ar-u-nu-latn").build());
            } else {
                // using arabic numbers - HOW TO MAKE THE DAYS AND YEAR IN ENGLISH NUMBER
                calendarPickerInitializer = calendarPickerView.init(today, nextYear.getTime(), new Locale("ar", "SA"));
            }
        }

@edenman
Copy link
Collaborator

edenman commented Oct 19, 2017

@arvi your best bet is to fork this library and manually change the formatters that you want to customize

@arvi
Copy link

arvi commented Oct 19, 2017

@edenman thanks for your prompt reply. May I know the file where the formatters are for day? What term can I CTRL+F in the library. Thanks a lot.

Never mind. I found it by searching for "setText" term :)

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

No branches or pull requests

5 participants