Translate Strings on Java Class

  • Replies:7
Nicola Pigozzo
  • Forum posts: 4

Jan 21, 2018, 2:22:25 PM via Website

Hi There,
I want to translate my android app in differennt languages, so I need to translate the words Shipping Date:, Time:, and others into different languages.

I have these Strings on display_load java class file:

    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>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)); 

And these on string.xml file:

String s = getResources().getString(R.string.shipping_date, shipping_date.toString());
String t = getResources().getString(R.string.shipping_time, shipping_time.toString());
String u = getResources().getString(R.string.shipping_address_c, shipping_address_address.toString());
String v = getResources().getString(R.string.transport_description_c, description.toString());
String w = getResources().getString(R.string.weight, weight.toString());
String x = getResources().getString(R.string.destination_date, shipping_date.toString());
String z = getResources().getString(R.string.destination_address, shipping_date.toString());
loaddate.setText(Html.fromHtml(s + t + u + v + w + x + z));

But I got only one row displayed on my android screen:
7it:21/01/2018

Could someone please tell me where I am doing wrong?

Thanks,

Nico

AC&MM

Reply
AC&MM
  • Forum posts: 1,155

Jan 21, 2018, 3:34:39 PM via Website

Nicola Pigozzo

Hi There,
I want to translate my android app in differennt languages, so I need to translate the words Shipping Date:, Time:, and others into different languages.

I have these Strings on display_load java class file:

    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>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)); 

And these on string.xml file:

String s = getResources().getString(R.string.shipping_date, shipping_date.toString());
String t = getResources().getString(R.string.shipping_time, shipping_time.toString());
String u = getResources().getString(R.string.shipping_address_c, shipping_address_address.toString());
String v = getResources().getString(R.string.transport_description_c, description.toString());
String w = getResources().getString(R.string.weight, weight.toString());
String x = getResources().getString(R.string.destination_date, shipping_date.toString());
String z = getResources().getString(R.string.destination_address, shipping_date.toString());
loaddate.setText(Html.fromHtml(s + t + u + v + w + x + z));

But I got only one row displayed on my android screen:
7it:21/01/2018

Could someone please tell me where I am doing wrong?

Thanks,

Nico

I didn't get ya, dude. Do you wanna translate some words of your programming code? Or do you wanna a code to make your app to translate automatically to another language?
If you wanna translate some words of your programming code, I can translate them to portuguese. Well, if you want it.

AC&MM
Galaxy J7 Pro
Moto X Force
Galaxy Tab S3

Nicola Pigozzo

Reply
Nicola Pigozzo
  • Forum posts: 4

Jan 21, 2018, 3:49:16 PM via Website

Hi @AC&MM ,

I want to translate some words in many languages so if someone will have let´s say french installed on phone, the app will be automatically in french language. To do that, as I know, I have to translate the strings. On my case posted before, I have only one string translated on screen when I start the emulator. I have actually 7 words to be translated in this case:

String s = getResources().getString(R.string.shipping_date, shipping_date.toString());
String t = getResources().getString(R.string.shipping_time, shipping_time.toString());
String u = getResources().getString(R.string.shipping_address_c, shipping_address_address.toString());
String v = getResources().getString(R.string.transport_description_c, description.toString());
String w = getResources().getString(R.string.weight, weight.toString());
String x = getResources().getString(R.string.destination_date, shipping_date.toString());
String z = getResources().getString(R.string.destination_address, shipping_date.toString());
loaddate.setText(Html.fromHtml(s + t + u + v + w + x + z));

Hope it is clear now,

Nico

— modified on Jan 21, 2018, 3:49:49 PM

AC&MM

Reply
AC&MM
  • Forum posts: 1,155

Jan 21, 2018, 3:57:55 PM via Website

Nicola Pigozzo

Hi @AC&MM ,

I want to translate some words in many languages so if someone will have let´s say french installed on phone, the app will be automatically in french language. To do that, as I know, I have to translate the strings. On my case posted before, I have only one string translated on screen when I start the emulator. I have actually 7 words to be translated in this case:

String s = getResources().getString(R.string.shipping_date, shipping_date.toString());
String t = getResources().getString(R.string.shipping_time, shipping_time.toString());
String u = getResources().getString(R.string.shipping_address_c, shipping_address_address.toString());
String v = getResources().getString(R.string.transport_description_c, description.toString());
String w = getResources().getString(R.string.weight, weight.toString());
String x = getResources().getString(R.string.destination_date, shipping_date.toString());
String z = getResources().getString(R.string.destination_address, shipping_date.toString());
loaddate.setText(Html.fromHtml(s + t + u + v + w + x + z));

Hope it is clear now,

Nico

Let me see if I really get ya. Do you wanna translate shipping date or shipping time, for example, in another language? Is that what you wanna? If it is, I'll translate to Portuguese. Does it help you anyway?

— modified on Jan 21, 2018, 4:07:37 PM

AC&MM
Galaxy J7 Pro
Moto X Force
Galaxy Tab S3

Nicola Pigozzo

Reply
Nicola Pigozzo
  • Forum posts: 4

Jan 21, 2018, 4:09:27 PM via Website

hi @AC&MM ,

yes you are right, that is what I am searching for. It will be great for me to see a peace of code working, so if you wanna put it into Portuguese language it will be great.

Thanks,

Nico

AC&MM

Reply
AC&MM
  • Forum posts: 1,155

Jan 21, 2018, 5:09:11 PM via Website

Nicola Pigozzo

hi @AC&MM ,

yes you are right, that is what I am searching for. It will be great for me to see a peace of code working, so if you wanna put it into Portuguese language it will be great.

Thanks,

Nico

Ok. Let's go.

String s = getResources().getString(R.string.shipping_date, shipping_date.toString());
String s = getResources().getString(R.string.data_de_envio, data_de_envio.toString());

String t = getResources().getString(R.string.shipping_time, shipping_time.toString());
String t = getResources().getString(R.string.prazo_de_entrega, prazo_de_entrega.toString());

String u = getResources().getString(R.string.shipping_address_c, shipping_address_address.toString());
String u = getResources().getString(R.string.endereco_de_entrega_c, endereco_de_entrega_endereco.toString());

String v = getResources().getString(R.string.transport_description_c, description.toString());
String v = getResources().getString(R.string.descricao_de_transporte_c, descricao.toString());

String w = getResources().getString(R.string.weight, weight.toString());
String w = getResources().getString(R.string.peso, peso.toString());

String x = getResources().getString(R.string.destination_date, shipping_date.toString());
String x = getResources().getString(R.string.data_de_entrega, data_de_envio.toString());

String z = getResources().getString(R.string.destination_address, shipping_date.toString());
String z = getResources().getString(R.string.endereco_de_destino, data_de_envio.toString());

loaddate.setText(Html.fromHtml(s + t + u + v + w + x + z));

I believe that's the better translation I could make. I'm learning programming code and this code is a high level for me.

I hope I've helped you.

PS. If there's something I wrote wrong, please, don't hesitate to correct me 'cos I'm a learner.

If you need something else, just let me know and I'll try to help you.

— modified on Jan 21, 2018, 5:10:14 PM

AC&MM
Galaxy J7 Pro
Moto X Force
Galaxy Tab S3

Nicola Pigozzo

Reply
Nicola Pigozzo
  • Forum posts: 4

Jan 21, 2018, 5:17:05 PM via Website

Hi @AC&MM ,

thank you for your translation, but I am actually searching for a solution to another Problem...

I hope someone will help me then...

AC&MM

Reply
AC&MM
  • Forum posts: 1,155

Jan 21, 2018, 5:20:46 PM via Website

Nicola Pigozzo

Hi @AC&MM ,

thank you for your translation, but I am actually searching for a solution to another Problem...

I hope someone will help me then...

Well, if I can help you...

AC&MM
Galaxy J7 Pro
Moto X Force
Galaxy Tab S3

Reply