-
Notifications
You must be signed in to change notification settings - Fork 115
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
Added useful method to get LocaleCode by country #2
base: master
Are you sure you want to change the base?
Conversation
Thank you for your having interest in nv-i18n. It seems to me that getByCode(String language, String country, boolean caseSensitive) should keep the current implementation to ensure that it returns a non-null value only when it finds the one that exactly matches the pair of the given country code and language code. On the other hand, your idea to find LocaleCode instances by country sounds good and should be implemented in a generic way. So, I'll implement getByCountry methods that return a list of LocaleCode instances whose country matches the specified one. Thank you, anyway. |
Good point. What about series of methods to the interface of enums:
Of course, all of above as public. Thats many methods to implement. What do you think? I can help with it. |
Sometimes it is technically and/or politically difficult to select one main language from among multiple official languages. For example, Singapore has four official languages: English, Chinese, Malay and Tamil, and which language should be regarded as main depends on what criterion is selected. Likewise, it is difficult to select one representing country for a given language. Polish and Japanese are simple cases and it is easy to select representing countries (Poland and Japan) for these, but it is difficult to select a representing country for Arabic. Therefore, I'd like to avoid adding getMainLanguage and getRepresentingCountry methods. Collection<?> getXxx() method candidates for CountryCode and LanguageCode (e.g. CountryCode.getLanguages()) would eventually have to refer to LocaleCode in their implementations. This implies that programmers can achieve the same functionalities by using LocaleCode.getByCountry and LocaleCode.getByLanguage. Therefore, it may be redundant to add getXxx() methods to CountryCode and LanguageCode. However, it may be worth adding such (redundant) alias methods for convenience, but at this moment, it is difficult for me to judge whether they are worth being added or not. Need some time to judge... I think that your suggestion to add getByCountry and getByLanguage to LocaleCode is good. |
* @return | ||
* A LocaleCode instance, or null if not found. | ||
*/ | ||
public static LocaleCode getByCountry(String country, boolean caseSensitive) { |
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.
I would also create a
getByCountry(String country)
which delegates to
getByCountry(country, false) .
Same as what is done with the getByCode methods.
New methods listed below:
were added to LocaleCode by: Thank you for your suggestions. Version 1.3 containing these methods is now able to be downloaded from Maven Central Repository. (but I forgot to change '1.2' to '1.3' in package-info.java... I'll fix the javadoc in the next release.) |
Nice changes :-). But about methods:
My story: I came up to a problem in my project to guess language based on internet address. I should print this language with SOME flag in select box(each language should has it flag). For ex.: addres If you don't like those methods, what do you think of sorting output of methods added in 6c69dae to represent most representative cases first? For ex.:
BTW.: You can use junit BTW2.: I notice that there are several missing |
Thank you for your informative comment, cardil. Regarding main languages and representing countries, it still sounds to me that the logic to select them should be implemented in upper layers or in other middleware (e.g. libraries over nv-i18n, application layer, your geolocation-related services, etc.) than nv-i18n library. But, thank you for explaining me real-world requirements. It game me some insights. JUnit API provides assertion methods for arrays, but I could not find assertion methods for List here: http://junit.sourceforge.net/javadoc/org/junit/Assert.html The list of LocaleCode was generated based on the output from Locale.getAvailableLocales() of Java SE 7 as I wrote in the javadoc. The reason LocaleCode for 'af' is not contained is just because Locale.getAvailableLocales() does not contain it. However, there is no convincing reason to avoid adding LocaleCode for 'af'. I should consider how to treat these missing entries. I need some time to find consistent and convincing reasons to add or not to add the missing entries. Anyway, thank you for your pointing out the issue. |
Ad. jUnit: New import static org.junit.Assert.*;
import static org.hamcrest.core.Is.is;
class ListTest {
@Test
public void testListPass()
{
List<String> actual = Arrays.asList("fee", "fi", "foe");
List<String> expected = Arrays.asList("fee", "fi", "foe");
System.out.println(actual == expected); // false
assertThat(actual, is(expected)); // passes
}
} Peace! |
Hi,
I've just added method to find first occurrence of
LocaleCode
by country ISO 3166-1 alpha-2 code.