[英]Load different files depending on language
I'm showing in a WebView a local html file with text. 我正在WebView中显示带有文本的本地html文件。
How can I load the english version of it depending on the language of the phone? 如何根据手机的语言加载英语版本?
Here is my code: 这是我的代码:
public class Seccion1 extends Fragment {
WebView mWebView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.seccion1, container, false);
mWebView = (WebView)rootView.findViewById(R.id.lectura_webView);
//Archivo de ejemplo. Cambiar por el adecuado.
mWebView.loadUrl("file:///android_asset/productividad/GooglePlay2.html");
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setDisplayZoomControls(false);
mWebView.setLongClickable(true);
mWebView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
return rootView;
}
@Override
public void onResume() {
super.onResume();
// Buscar AdView como recurso y cargar una solicitud.
AdView adView = (AdView)this.getView().findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
Uri uri = Uri.parse("https://www.twitter.com/XXX");
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
return true;
}
return super.onOptionsItemSelected(item);
}
} }
Thank you! 谢谢!
PD: I'm adding this text because it says thay my post is mostly code. PD:我添加此文本是因为它说我的帖子主要是代码。 I think the question is clear enough.
我认为问题很明确。
Edit 1: 编辑1:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.seccion4, container, false);
mWebView = (WebView)rootView.findViewById(R.id.lectura_webView);
//Archivo de ejemplo. Cambiar por el adecuado.
//mWebView.loadUrl("file:///android_asset/textos_ES/Extra.html");
String language= Locale.getDefault().getLanguage();
String imageUrl="";
if (language.equals("Spanish")){
imageUrl="file:///android_asset/textos/Extra.html";
}
else {
imageUrl="file:///android_asset/textos/Ejemplo1.html";
}
mWebView.loadUrl(imageUrl);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setDisplayZoomControls(false);
mWebView.setLongClickable(true);
mWebView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
return rootView;
}
I think @Duggu has made it very clear. 我认为@Duggu非常清楚。 You can try something like
您可以尝试类似
String language=Locale.getDefault().getLanguage();
String imageUrl="";
if (language.equals("English")){
imageUrl="english.html"
}
if (language.equals("French")){
imageUrl="french.html"
}
webView.loadUrl(imageUrl);
Try below code :- 尝试下面的代码:-
Locale.getDefault().getDisplayLanguage();
Above method return language of current device . 以上方法返回当前设备的语言。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.