Skip to content

Instantly share code, notes, and snippets.

@udacityandroid
Last active February 6, 2023 17:58
Show Gist options
  • Save udacityandroid/759b8b4c9ed9e6806e90 to your computer and use it in GitHub Desktop.
Save udacityandroid/759b8b4c9ed9e6806e90 to your computer and use it in GitHub Desktop.
Android for Beginners : Spanish Localization Solution. This would be saved in the res/values-es/strings.xml file.
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Title for the application. [CHAR LIMIT=12] -->
<string name="app_name">Sólo Java</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="name">Nombre</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="toppings">Ingredientes</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="whipped_cream">Crema batida</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="chocolate">Chocolate</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="quantity">Cantidad</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=5] -->
<string name="initial_quantity_value">2</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="order">Ordenar</string>
<!--
Name for the order summary. It will be shown in the format of "Name: Amy" where Amy is the
user's name. [CHAR LIMIT=NONE]
-->
<string name="order_summary_name">Nombre: <xliff:g id="name" example="Amy">%s</xliff:g></string>
<!--
Whipped cream topping for the order summary. It will be shown in the format of
"Add whipped cream? true" or "Add whipped cream? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_whipped_cream">Agregue la crema batida? <xliff:g id="addWhippedCream" example="true">%b</xliff:g></string>
<!--
Chocolate topping for the order summary. It will be shown in the format of
"Add chocolate? true" or "Add chocolate? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_chocolate">Agregue el chocolate? <xliff:g id="addChocolate" example="true">%b</xliff:g></string>
<!--
Quantity of coffee cups for the order summary. It will be shown in the format of
"Quantity: 2", where 2 is the number of cups ordered. [CHAR LIMIT=NONE]
-->
<string name="order_summary_quantity">Cantidad: <xliff:g id="quantity" example="2">%d</xliff:g></string>
<!--
Total price for the order summary. It will be shown in the format of
"Total: $10" where $10 is the price. [CHAR LIMIT=NONE]
-->
<string name="order_summary_price">Total: <xliff:g id="price" example="$10">%s</xliff:g></string>
<!-- Thank you message for the order summary. [CHAR LIMIT=NONE] -->
<string name="thank_you">¡Gracias!</string>
<!--
Subject line for the order summary email. It will be in the format of
"Just Java order for Amy" where Amy is the user's name. [CHAR LIMIT=NONE]
-->
<string name="order_summary_email_subject">Sólo java para <xliff:g id="name" example="Amy">%s</xliff:g></string>
</resources>
@alvee-unb
Copy link

@Naruto-uchiha24 Are you still facing the same issue? Have you tried to keep logs where the intent was called from?

@SafiaBakour
Copy link

رغم اني املك تطبيق البريد الالكتروني في هاتفي لكن لم يستطع تطبيق جاست جافا استدعاءه لارسال ملخص الطلب
اعني انني عندما اضغط على زر الطلب لا يبعث الغرض للبريد الالكتروني
@RequiresApi(api = Build.VERSION_CODES.N)
public void submitOrder(View view) {
// Figure out if the user wants whipped cream topping
CheckBox WhippedCreamCheckBox = (CheckBox) findViewById(R.id.add_whipped_cream);
boolean hasWhippedCream = WhippedCreamCheckBox .isChecked();

    // Figure out if the user wants chocolate topping
   CheckBox  chocolateCheckBox= findViewById(R.id.chocolate_checkbox);
   boolean hasChocolate = chocolateCheckBox.isChecked();

   EditText nameField = findViewById(R.id.name_of_user);
  String name =nameField.getText().toString();

  int price = calculatePrice(hasWhippedCream,hasChocolate);
  String priceMessage = creatOrderSummary(price,hasWhippedCream, hasChocolate,name);


Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_SUBJECT,"Just java order for"+name);
intent.putExtra(Intent.EXTRA_TEXT,priceMessage);

 displayMessage(priceMessage);


 

}

وهدا هو الكود الخاص بالغرض ارجو المساعدة كي استطيع متابعة الدروس

@engsarahfouad
Copy link

Arabic Version
النسخة العربية

الجافا فقط

<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="name">الأسم</string>

<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="toppings">إضافات</string>

<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="whipped_cream">كريمه</string>

<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="chocolate">شوكولاتة</string>

<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="quantity">الكميه</string>

<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=5] -->
<string name="initial_quantity_value">٢</string>

<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="order">أطلب</string>

<!--
  Name for the order summary. It will be shown in the format of "Name: Amy" where Amy is the
  user's name. [CHAR LIMIT=NONE]
-->
<string name="order_summary_name">: الأسم<xliff:g id="name" example="Amy">%s</xliff:g></string>

<!--
  Whipped cream topping for the order summary. It will be shown in the format of
  "Add whipped cream? true" or "Add whipped cream? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_whipped_cream">إضافة كريمه ؟ <xliff:g id="addWhippedCream" example="true">%b</xliff:g></string>

<!--
  Chocolate topping for the order summary. It will be shown in the format of
  "Add chocolate? true" or "Add chocolate? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_chocolate">إضافة شوكولاتة؟<xliff:g id="addChocolate" example="true">%b</xliff:g></string>

<!--
  Quantity of coffee cups for the order summary. It will be shown in the format of
  "Quantity: 2", where 2 is the number of cups ordered. [CHAR LIMIT=NONE]
-->
<string name="order_summary_quantity">: الكميه<xliff:g id="quantity" example="2">%d</xliff:g></string>

<!--
  Total price for the order summary. It will be shown in the format of
  "Total: $10" where $10 is the price. [CHAR LIMIT=NONE]
-->
<string name="order_summary_price">:الأجمالى <xliff:g id="price" example="$10">%s</xliff:g></string>

<!-- Thank you message for the order summary. [CHAR LIMIT=NONE] -->
<string name="thank_you">شكراَ</string>

<!--
  Subject line for the order summary email. It will be in the format of
  "Just Java order for Amy" where Amy is the user's name. [CHAR LIMIT=NONE]
-->
<string name="order_summary_email_subject"> الجافا فقط إلى <xliff:g id="name" example="Amy">%s</xliff:g></string>

السلام عليكم
ممكن توضيح لx liff ؟ للغة العربية

@mateendev3
Copy link

Turkish Translation

Sadece Java Topingler Teşekkürler Krem şanti Çikolata Miktar Emir İsim: %s Miktar: %s Çırpılmış krema ekler misiniz? %s Çikolata ekle?? %s Toplam: ₺%f İsim iki Sadece Java Siparişi

@rebeccazee
Copy link

For the strings that use booleans variables, I did two types of strings for the true and false. For order_summary_whipped_cream and order_summary_chocolate I got rid of the xliff:g and used this code:
English

<!--
    Whipped cream topping for the order summary. It will be shown in the format of
    "Add whipped cream? true" or "Add whipped cream? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_whipped_cream_true">Add whipped cream? true</string>
<string name="order_summary_whipped_cream_false">Add whipped cream? false</string>

<!--
    Chocolate topping for the order summary. It will be shown in the format of
    "Add chocolate? true" or "Add chocolate? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_chocolate_true">Add chocolate? true</string>
<string name="order_summary_chocolate_false">Add chocolate? false</string>

`Spanish

<!--
    Whipped cream topping for the order summary. It will be shown in the format of
    "Add whipped cream? true" or "Add whipped cream? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_whipped_cream_true">Agregue la crema batida? verdadero</string>
<string name="order_summary_whipped_cream_false">Agregue la crema batida? falso</string>

<!--
    Chocolate topping for the order summary. It will be shown in the format of
    "Add chocolate? true" or "Add chocolate? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_chocolate_true">Agregue el chocolate? verdadero</string>
<string name="order_summary_chocolate_false">Agregue el chocolate? falso</string>

Then in the java file, I used the conditional operator, ?:, to set the values.to the boolean variables.

@imohdalam
Copy link

imohdalam commented Feb 5, 2022

Hindi Version

 <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <string name="app_name">JavaActivity</string>
    <string name="chocolate">चॉकलेट</string>
    <string name="whipped_cream">मार पड़ी क्रीम</string>
    <string name="order">आदेश</string>
    <string name="toppings">सामग्री</string>
    <string name="order_summary">आदेश सारांश</string>
    <string name="quantity">"परिमाण: "</string>
    <string name="thank_you">धन्यवाद!!</string>
    <string name="Whipped_Cream">"व्हीप्ड क्रीम जोड़ें? "</string>
    <string name="Chocolate">"चॉकलेट जोड़ें? "</string>
    <string name="name_text">" नाम: <xliff:g example="Amy" id="name">%s</xliff:g>"</string>
    <string name="total">"कुल: "</string>
    <string name="name">नाम</string>
</resources>

@YazanMunirA
Copy link

اسم التطبيق الاضافات شكرا لكم معلومات الطلب اكمل $0 اضف كريمة ? %b أضف شكولاته؟ القيمه %d المجموع%s
<string name="order_summary_name"> الاسم<xliff:g id="quantity" example="Yazan">%s</xliff:g></string>

Java>>>>
package com.example.justjava;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

/**

  • This app displays an order form to order coffee.
    */
    public class MainActivity extends AppCompatActivity {
    int quantity;

    @OverRide
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    }
    /**

    • This method is called when the plus button is clicked. Intent intent = new Intent(Intent.ACTION_SENDTO);
    •     intent.setData(Uri.parse("mailto:")); // only email apps should handle this
      
    •     intent.putExtra(Intent.EXTRA_SUBJECT, "just jvaa" + editable);
      
    •     if (intent.resolveActivity(getPackageManager()) != null) {
      
    •         startActivity(intent);
      
    •     }
      

    */
    public void increment(View view) {

     if (quantity==15){
    
         Toast.makeText(this, " you cannot have more than 15  ", Toast.LENGTH_SHORT).show();
         return;
     }
     quantity=++quantity;
     displayQuantity(quantity);
    

    }
    /**

    • This method is called when the sub button is clicked.
      /
      public void decrement(View view) {
      if (quantity<1){
      Toast.makeText(this, "you cannot have less 1 cup", Toast.LENGTH_SHORT).show();
      return;
      }
      quantity=--quantity;
      displayQuantity(quantity);
      }
      /
      *

    • This method is called when the order button is clicked.
      */
      @SuppressLint("QueryPermissionsNeeded")
      public void submitOrder(View view) {
      EditText name = (EditText) findViewById(R.id.EditText_view);
      String Name = name.getText().toString(); // Editable Name = editText.getText();

      CheckBox isCheck = (CheckBox) findViewById(R.id.checkbox);
      boolean hasWhippedCream = isCheck.isChecked();

      CheckBox ischocolate = (CheckBox) findViewById(R.id.chocolate_checkbox);
      boolean hasChocolate = ischocolate.isChecked();

      int price = calculatePrice(hasWhippedCream, hasChocolate);
      String priceMassage = CsreateOrderSummary(price, hasWhippedCream, hasChocolate, Name);

      Intent intent = new Intent(Intent.ACTION_SENDTO);
      intent.setData(Uri.parse("mailto:")); // only email apps should handle this
      intent.putExtra(Intent.EXTRA_SUBJECT, "Just Java order for "+ Name);
      intent.putExtra(Intent.EXTRA_TEXT, priceMassage);
      startActivity(intent);

       displayMessage(priceMassage);
      

    }

    private void displayQuantity(int number) {
    TextView quantityTextView = findViewById(R.id.quantity_text_view); // num of cups
    quantityTextView.setText("" + number);
    }

    /**

    • This method displays the given text on the screen.
      */
      private void displayMessage(String message) {
      TextView priceTextView = (TextView) findViewById(R.id.summary_order_text_view); // string
      priceTextView.setText(message);
      }

    /**

    • Calculate thr taxes of Saudi Arabia \if (hasWhippedCream || hasChocolate){
    •         price = calculatePrice() + 5 ;
      
    •     } if (hasWhippedCream  && hasChocolate){
      
    •         price = calculatePrice() + 10;
      
    •     } else if(hasChocolate|| hasWhippedCream){
      
    •         Toast.makeText(this, "have you add Toppings ", Toast.LENGTH_SHORT).show();
      
    • @return the value of taxes
      /
      private int calculatePrice( boolean addWhippedCream ,boolean addChocolate ) {
      int price = 5;
      if (addWhippedCream){
      price = price +1; }
      if (addChocolate){
      price = price+2; }
      return quantity
      price;

    }
    /**
    * Create summary of the order.

  •   * @param name of the customer
    
  • @param price of the order

  • @param addWhippedCream is whether or not the user wants whipped cream topping

  • @param hasChoco is whether or not the user wants chocolate topping
    * @return text summary
    */
    private String CsreateOrderSummary (int price , boolean addWhippedCream,boolean hasChoco,String name ) {

     String priceMessage = getString(R.string.order_summary_name)+ name+":";
     priceMessage += "\n" +getString(R.string.add_whipped) + "?"+addWhippedCream;
     priceMessage += "\n"+getString(R.string.add_chocolat) + "?"+ hasChoco;
      priceMessage +=    quantity+"\n"+getString(R.string.quantity) ;
     priceMessage += "\n"+getString(R.string.Total) + price;
     priceMessage += "\n"+ getString(R.string.thank_you);
    
    
     return priceMessage;
    

    }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment