将 Java 和 Json 转换为用于 android 应用程序翻译的字符串
Conver Java and Json into String for android app translation
我在 android 上有一个 Java Class 和这些字符串,我想将它们翻译成其他语言:
String s = "<b>Shipping Date:</b>" + shipping_date.toString();
loaddate.setText(Html.fromHtml(s));
String t = "<b>Time:</b>" + shipping_time.toString();
loadtime.setText(Html.fromHtml(t));
String u = "<b>c.getString(shipping_address)</b>" + shipping_address_address.toString();
loadplace.setText(Html.fromHtml(u));
String v = "<b>Description:</b>" + description.toString();
txtdesc.setText(Html.fromHtml(v));
String w = "<b>Weight:</b>" + weight.toString() + " KG";
txtweight.setText(Html.fromHtml(w));
String x = "<b>Destination Date:</b>" + destination_date.toString();
txtdestdate.setText(Html.fromHtml(x));
String y = "<b>Time:</b>" + destination_time.toString();
txtdesttime.setText(Html.fromHtml(y));
String z = "<b>Destination Address:</b>" + destination_address_address.toString();
txtdestplace.setText(Html.fromHtml(z));
有人可以帮我吗?
谢谢,
妮可
您必须将文本提取到 strings.xml 资源文件中,使用占位符并转义 html 标签
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="shipping_date">"<b>Shipping Date: </b> %1$s"</string>
</resources>
在您的代码中,您可以调用
String s= getResources().getString(R.string.shipping_date, shipping_date.toString());
loaddate.setText(Html.fromHtml(s));
然后您可以为不同的语言创建不同的 strings.xml 文件
更多信息:
我在 android 上有一个 Java Class 和这些字符串,我想将它们翻译成其他语言:
String s = "<b>Shipping Date:</b>" + shipping_date.toString();
loaddate.setText(Html.fromHtml(s));
String t = "<b>Time:</b>" + shipping_time.toString();
loadtime.setText(Html.fromHtml(t));
String u = "<b>c.getString(shipping_address)</b>" + shipping_address_address.toString();
loadplace.setText(Html.fromHtml(u));
String v = "<b>Description:</b>" + description.toString();
txtdesc.setText(Html.fromHtml(v));
String w = "<b>Weight:</b>" + weight.toString() + " KG";
txtweight.setText(Html.fromHtml(w));
String x = "<b>Destination Date:</b>" + destination_date.toString();
txtdestdate.setText(Html.fromHtml(x));
String y = "<b>Time:</b>" + destination_time.toString();
txtdesttime.setText(Html.fromHtml(y));
String z = "<b>Destination Address:</b>" + destination_address_address.toString();
txtdestplace.setText(Html.fromHtml(z));
有人可以帮我吗?
谢谢,
妮可
您必须将文本提取到 strings.xml 资源文件中,使用占位符并转义 html 标签
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="shipping_date">"<b>Shipping Date: </b> %1$s"</string>
</resources>
在您的代码中,您可以调用
String s= getResources().getString(R.string.shipping_date, shipping_date.toString());
loaddate.setText(Html.fromHtml(s));
然后您可以为不同的语言创建不同的 strings.xml 文件
更多信息: