comparison artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultCallMeta.java @ 50:0b04fa8a19c6

Better implementation for fetching the preferred locale via meta of call context. artifacts/trunk@176 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 02 Oct 2009 10:02:15 +0000
parents 823850c63d95
children 3a668da76463
comparison
equal deleted inserted replaced
49:823850c63d95 50:0b04fa8a19c6
26 public Locale getPreferredLocale(Locale [] locales) { 26 public Locale getPreferredLocale(Locale [] locales) {
27 if (locales == null || locales.length == 0) { 27 if (locales == null || locales.length == 0) {
28 return null; 28 return null;
29 } 29 }
30 30
31 return locales[0]; 31 Locale best = null;
32 float quality = -Float.MAX_VALUE;
33
34 for (int i = 0; i < locales.length; ++i) {
35 Locale wish = locales[i];
36 String wishLanguage = wish.getLanguage();
37
38 for (int j = 0; j < languages.length; ++j) {
39 PreferredLocale have = languages[j];
40 Locale haveLocale = have.getLocale();
41 if (haveLocale.getLanguage().equals(wishLanguage)) {
42 float haveQuality = have.getQuality();
43 if (haveQuality > quality) {
44 quality = haveQuality;
45 best = wish;
46 }
47 break; // Languages should not contain
48 // same locale twice.
49 }
50 }
51 }
52
53 return best == null
54 ? locales[0]
55 : best;
32 } 56 }
33 } 57 }
34 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: 58 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org