You can use Accept-Language property of http header to set Locale , but how we can get http header property in flex application ?
using request.getHeader("accept-language") method we can get http Header accept-language property , but this is jsp method . so for calling jsp from flex application I used flash variable . or youcan also call jsp from java script and java script from flex using external interface library .
I wrap my main.swf file in main. jsp page instead of main.html.
Save as main.html file by main.jsp and modify flash variable by
AC_FL_RunContent(
"src", "playerProductInstall",
"FlashVars","MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+'&setLocale=<%=request.getHeader("Accept-Language")%>'+"",
"width", "100%",
"height", "100%",
"align", "middle",
"id", "main",
"quality", "high",
"bgcolor", "#869ca7",
"name", "main",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);
now you can access setLocale variable from action script usingvar locale:String = Application.application.parameters.setLocale;calling jsp page from javascript and javascript from flexthis is my Locale.jsp page<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%! String language;
public String getLanguage(){
return language;
}
%>
<%language= request.getHeader("accept-language");%>
<%=getLanguage() %>
it will return accept language property of http header .
Now I am calling jsp page from javascript , i am going to write java script code in my main .html
<script type="text/javascript">
function getLocale() {
var xmlHttp;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
} catch (e) {
//Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.open("POST","Locale.jsp",true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4) {
return (xmlHttp.responseText);
}
}
}
</script>
now you can access getLocale() variable from action script using external interface
var langauge:String = ExternalInterface.call("getLocale");
Cheers………