Hi Clayton,
Clayton wrote:
Doesn´t this language selector extension accept bug reports somewhere
IMHO this is just very clearly in violation of
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
and thus just simply implemented the wrong way.
Such extension is pretty useless if it doesn´t adhere to the accepted
HTTP Protocol standards and better even not being used if it doesn´t
work as it would be supposed to work.
Languages must only be sorted by the additional "q" value if present,
defaulting to 1.0 for those where it is not present.
I haven't yet looked into submitting a bug report on this extension.
It's on my list if soemone else here doesn't manage to do so first.
Well I just had a look into the source code, provided that I found the
right extension, are we talking about this one
http://www.mediawiki.org/wiki/Special:ExtensionDistributor/LanguageSelector)
and there is a big comment
#FIXME: qualifiers are ignored, order is relevant!
in the code so obviously it is a known issue
Judging from what I have seen so far that Selector also just ignores
language variants such as "en-US" versus "en-GB" and 'normalizes' them
to in these two cases "en".
If we don't use such an extension, what can we do to provide the Wiki
interface in localized languages to people who do not have a Wiki
account? Not everyone is able to manage in English. Put it another
way, imagine that the interface defaulted to Russian if you were not
logged in. Would those of us who cannot read Russian be able to
navigate the Wiki interface well enough to register and then set the
language to one we can read/understand? I know I couldn't in this case.
At least with this extension in place, we make an effort to provide the
Wiki navigation and interface in the reader's preferred language.
I agree to that offering only a partly working language selector might
be better than none at all, but maybe we can improve on that.
Is there a better solution? if there is one, we can certainly install
it an use it. I just haven't yet found one that was better.
Well we probably just need a volunteer with php and mediawiki hacking
skills to fix that extension.
Following is some code on how I do language selection for a given list
of available languages compared to the users preferences in java maybe
someone on the list can use that and translate it to php and fix the
extension.
public static String getPreferredLanguage(HttpServletRequest req,
String[] available) {
if ( available==null ) {
return "en-US";
}
acceptLanguages=req.getHeader("Accept-Language");
if ( acceptLanguages == null ) {
return available[0];
}
String[] accept=StringUtil.split(acceptLanguages,",");
double maxq_first=-1.0;
double maxq_second=-1.0;
String lang_first=null;
String lang_second=null;
int pos_first=0;
int pos_second=0;
for ( int j=0; j<accept.length; j++ ) {
for ( int i=0; i<available.length; i++ ) {
int k=accept[j].indexOf(';');
double q=0.0;
String l1=available[i];
String l2=null;
if ( k == -1 ) {
q=1.0;
l2=accept[j];
} else {
l2=accept[j].substring(0,k).trim();
String qspec=accept[j].substring(k);
k=qspec.indexOf("q=");
if ( k==-1 ) {
q=1.0;
} else {
qspec=qspec.substring(k+2).trim();
try {
q=Double.parseDouble(qspec);
} catch ( NumberFormatException nfe ) {
q=1.0;
}
}
}
l1=toStdLocale(l1);
l2=toStdLocale(l2);
if ( l2.equals(l1) ) {
if (q > maxq_first ) {
lang_first=l1;
maxq_first=q;
pos_first=j;
}
} else {
// second try compare while ignoring the variant
k=l1.indexOf("-");
if ( k > -1 ) {
l1=l1.substring(0,k);
}
String l2b=l2;
k=l2b.indexOf("-");
if ( k > -1 ) {
l2b=l2b.substring(0,k);
}
if ( l2b.equals(l1) && q > maxq_second ) {
lang_second=l2;
maxq_second=q;
pos_second=j;
}
}
}
}
if ( (lang_first != null) && (lang_second != null) ) {
if ( maxq_first >= maxq_second ) {
if ( (maxq_first == maxq_second) &&
(pos_second<pos_first) ) {
return lang_second;
}
return lang_first;
} else {
return lang_second;
}
}
if ( lang_first != null ) {
return lang_first;
}
if ( lang_second != null ) {
return lang_second;
}
return available[0];
}
private static String toStdLocale(String lang) {
if (lang == null ) {
return null;
}
int i=lang.indexOf('-');
if ( i == -1 ) {
return lang.toLowerCase(Locale.US);
}
StringBuffer buf=new
StringBuffer(lang.substring(0,i).toLowerCase(Locale.US));
buf.append("-");
if ( i<lang.length() ) {
buf.append(lang.substring(i+1).toUpperCase(Locale.US));
}
return buf.toString();
}
C.
Kind regards,
Bernd Eilers
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]