Fwd: Question about Locale

0 views
Skip to first unread message

Rob LaRubbio

unread,
Apr 3, 2012, 2:56:11 PM4/3/12
to motec...@googlegroups.com
Moving this discussion to motech-dev.

Is there a standard java way to define and access a users locale?

This trail talks about using a locale once it is defined, I'm not sure what the best practice is for setting it.

http://docs.oracle.com/javase/tutorial/i18n/index.html

-Rob

-------- Original Message --------
Subject: Question about Locale
Date: Tue, 03 Apr 2012 13:28:52 +0200
From: Łukasz Lewczyński <llewc...@soldevelo.com>
To: rlar...@grameenfoundation.org
CC: jslaw...@soldevelo.com


Hi,

I currently work on motech project and I have problem with tests when I 
change locale to non-english locale. I fixed the tests by adding 
information about english locale, but I think that isn't good solution. 
My question is how motech should gets information about user locale ?

Thanks
Lukasz

Jakub Sławiński

unread,
Apr 7, 2012, 1:06:46 PM4/7/12
to motec...@googlegroups.com

Hi,

I think the question was not clear enough. The problem is that MOTECH is
not using locales in the consistent way, which looks like a bug. You can
see this after changing your system locale to something different than
English. When you do this, then you will see the similar test failure:

shouldReturnNextApplicableDayForTheGivenDate(org.motechproject.server.messagecampaign.domain.message.RepeatingCampaignMessageTest)
Time elapsed: 0.023 sec <<< FAILURE!
java.lang.AssertionError:
Expected: is "Wednesday"
got: "środa"

at org.junit.Assert.assertThat(Assert.java:778)
at org.junit.Assert.assertThat(Assert.java:736)
at
org.motechproject.server.messagecampaign.domain.message.RepeatingCampaignMessageTest.shouldReturnNextApplicableDayForTheGivenDate(RepeatingCampaignMessageTest.java:58)

After looking at the code you will see, that you must use English week
day names when specifying for example weekDaysApplicable, but the method
applicableWeekDayInNext24Hours() returns week day names in the system
locale.

There is a couple of solutions available:
* MOTECH should have English locale hard-coded in all the places
(currently English is hard-coded in part of the code only)
* MOTECH should work with the system locale (which is currently true
when the system locale is English)
* MOTECH should have the possibility to set locale via configuration
properties

So, which of the solutions is the best one? Or maybe you would like to
fix the problem in a different way?


Regards,
Jakub.

Vivek Singh

unread,
Apr 9, 2012, 4:16:17 AM4/9/12
to motec...@googlegroups.com
>> MOTECH should have the possibility to set locale via configuration properties
This is my personal preference. I like this because I can choose to run application in any locale irrespective of machine. This can be useful when running multiple application for two different customers on same machine. But we didn't go with that when we faced a similar question related timezone because we didn't have a use case of that yet.

>> MOTECH should work with the system locale (which is currently true 
when the system locale is English)
If not above then this would be my preference, as long as the tests don't use it. In other words the tests should not have hardcoded "Wednesday" in it. I like that fact that we have you guys working on the project, otherwise some of us (in India & US) would never notice them.

2012/4/7 Jakub Sławiński <jslaw...@soldevelo.com>
--
You received this message because you are subscribed to the Google Groups "MoTeCH Developer" group.
To post to this group, send email to motec...@googlegroups.com.
To unsubscribe from this group, send email to motech-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/motech-dev?hl=en.




--
Vivek Singh | +91 98452 32929http://sites.google.com/site/petmongrels | petmongrels@twitter

Rob LaRubbio

unread,
Apr 10, 2012, 6:20:47 PM4/10/12
to motec...@googlegroups.com
I do think locale should be set via a configuration.

For this specific example, should the API be accepting and returning strings or instead using enums with helper APIs that convert them to strings using the locale?

-Rob

Vivek Singh

unread,
Apr 11, 2012, 3:53:17 AM4/11/12
to motec...@googlegroups.com
Since this is internal to the module it can return DateTime.Property instead of the text.

Instead of:
applicableDateTime.dayOfWeek().getAsText()
Return:
applicableDateTime.dayOfWeek()

and in the org.motechproject.server.messagecampaign.scheduler.RepeatingProgramScheduleHandler#handleEvent convert it to org.motechproject.model.DayOfWeek enum, as this is where this module would interact with other modules.

Jakub Sławiński

unread,
Apr 11, 2012, 6:09:23 AM4/11/12
to motec...@googlegroups.com

Hi,

what about returning DayOfWeek enum directly? This should be a more
consistent solution, because we will be operating only with DayOfWeek
enum across the framework and we will not need any converting.


Regards,
Jakub.

On 04/11/2012 09:53 AM, Vivek Singh wrote:
> Since this is internal to the module it can return DateTime.Property
> instead of the text.
>
> Instead of:
> applicableDateTime.dayOfWeek().getAsText()
> Return:
> applicableDateTime.dayOfWeek()
>
> and in
> the org.motechproject.server.messagecampaign.scheduler.RepeatingProgramScheduleHandler#handleEvent
> convert it to org.motechproject.model.DayOfWeek enum, as this is where this
> module would interact with other modules.
>
> On 11 April 2012 03:50, Rob LaRubbio <rlar...@grameenfoundation.org>wrote:
>
>> I do think locale should be set via a configuration.
>>
>> For this specific example, should the API be accepting and returning
>> strings or instead using enums with helper APIs that convert them to
>> strings using the locale?
>>
>> -Rob
>>
>>
>> On 4/9/12 1:16 AM, Vivek Singh wrote:
>>
>> *>> MOTECH should have the possibility to set locale via

>> configuration properties*


>> This is my personal preference. I like this because I can choose to run
>> application in any locale irrespective of machine. This can be useful when
>> running multiple application for two different customers on same machine.
>> But we didn't go with that when we faced a similar question related
>> timezone because we didn't have a use case of that yet.
>>

>> *>> MOTECH should work with the system locale (which is currently true **when
>> the system locale is English)*


>> If not above then this would be my preference, as long as the tests don't
>> use it. In other words the tests should not have hardcoded "Wednesday" in
>> it. I like that fact that we have you guys working on the project,
>> otherwise some of us (in India & US) would never notice them.
>>

>> 2012/4/7 Jakub S�awi�ski <jslaw...@soldevelo.com>


>>
>>>
>>> Hi,
>>>
>>> I think the question was not clear enough. The problem is that MOTECH is
>>> not using locales in the consistent way, which looks like a bug. You can
>>> see this after changing your system locale to something different than
>>> English. When you do this, then you will see the similar test failure:
>>>
>>>
>>> shouldReturnNextApplicableDayForTheGivenDate(org.motechproject.server.messagecampaign.domain.message.RepeatingCampaignMessageTest)
>>> Time elapsed: 0.023 sec <<< FAILURE!
>>> java.lang.AssertionError:
>>> Expected: is "Wednesday"

>>> got: "�roda"

Vivek Singh

unread,
Apr 11, 2012, 6:13:34 AM4/11/12
to motec...@googlegroups.com
We would require to convert at one place or other from Joda version to our version. I would leave it to you where you want to do it. My thoughts were to stick to Joda for as much as possible (inside the module) as it has more functionality that our enum. If we do that then we can use them with other Joda libraries, which we cannot if we convert too early.

2012/4/11 Jakub Sławiński <jslaw...@soldevelo.com>
>> 2012/4/7 Jakub Sławiński <jslaw...@soldevelo.com>

>>
>>>
>>> Hi,
>>>
>>> I think the question was not clear enough. The problem is that MOTECH is
>>> not using locales in the consistent way, which looks like a bug. You can
>>> see this after changing your system locale to something different than
>>> English. When you do this, then you will see the similar test failure:
>>>
>>>
>>> shouldReturnNextApplicableDayForTheGivenDate(org.motechproject.server.messagecampaign.domain.message.RepeatingCampaignMessageTest)
>>>  Time elapsed: 0.023 sec  <<< FAILURE!
>>> java.lang.AssertionError:
>>> Expected: is "Wednesday"
>>>     got: "środa"

Jakub Sławiński

unread,
Apr 11, 2012, 7:06:30 AM4/11/12
to motec...@googlegroups.com

Hi,

I decided to use DayOfWeek, but this of course can be changed very
easily. I also fixed some other problems related to locales and now the
core platform can be built without any test failures on the machines
with a different locale than English.

Regarding locale setting via configuration - should we look at this now,
or we can leave it as-is (i.e. MOTECH has English locale hard-coded in
some places) for the near future?


Regards,
Jakub.

Rob LaRubbio

unread,
Apr 12, 2012, 11:53:36 AM4/12/12
to motec...@googlegroups.com
I'll add setting local as an issue on google code and then migrate it
once I've got the jira instance up.

-Rob

>>>>> otherwise some of us (in India& US) would never notice them.

Reply all
Reply to author
Forward
0 new messages