how to return arabic translations to resource id?

0

I'm working on an app that contain sqlite database, the concept of the app is to enter and save data that translation part is the problem has two languages Arabic and English when the user insert new product he has to select the item type from spinner (which is translated to Arabic )when the user changes the device language the saved data (item type is not being translated) I've tried two methods to solve this but they are not working with Arabic language

The first method is returning wrong translated value (its return another arabic word not the the expected word ):

 public int getStringResourceByName(Context context, String name) {
    int id = 0;
    Field[] fields = R.string.class.getFields();
    for (Field field : fields) {

        try { //field.getName();
            id = field.getInt(name);

            return id;
        } catch (Exception ex) {
            break;
        }
    }

    return id;

}

The adapter code

textViewquantity.setText(context.getString(R.string.last_added_qty)+" " + repo.getQuantity() + " "+context.getResources().getString(mdatabase.getStringResourceByName (context, repo.getItemsType())));

the second method is working fine with English data but when I insert data in Arabic language the app crashes

The second method code

public static int getResId(String resName, Class<?> c) {

    try {
        Field idField = c.getDeclaredField(resName);
        return idField.getInt(idField);
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}

the code in the adapter

 textViewquantity.setText(context.getString(R.string.last_added_qty)+" " + repo.getQuantity() + " " + context.getResources().getString(mdatabase.getResId(repo.getItemsType(),R.string.class)));

and it's giving me this result with Arabic language android.content.res.Resources$NotFoundException: String resource ID #0xffffffff

where did I go wrong with these methods, please help i've tried everything any suggestion !?

<resources
xmlns:tools="http://schemas.android.com/tools">
<string name="app_name">Repo</string>
<string name="table_name">repository</string>

<string name="db_name">Repository</string>
<string name="newInput">New Input</string>
<string name="newOutput">New Output</string>
<string name="repository">Repository</string>
<string name="aboutRepo">About Repo</string>
<string-array name="prices">
    <item>@string/USD</item>
    <item>@string/EUR</item>
    <item>@string/SYP</item>
    <item>@string/LL</item>
    <item>@string/egp</item>
    <item>@string/QAR</item>
    <item>@string/AED</item>
    <item>@string/SAR</item>
    <item>@string/IQD</item>
    <item>@string/JOD</item>
    <item>@string/YER</item>
    <item>@string/LYD</item>
    <item>@string/SDG</item>
    <item>@string/MAD</item>
    <item>@string/TND</item>
    <item>@string/KWD</item>
    <item>@string/dzd</item>
    <item>@string/MRO</item>
    <item>@string/BHD</item>
    <item>@string/OMR</item>
    <item>@string/SOS</item>
    <item>@string/FDJ</item>
    <item>@string/GBP</item>
    <item>@string/TRY</item>
    <item>@string/RUB</item>
    <item>@string/JPY</item>
    <item>@string/AUD</item>

</string-array>
<string name="USD">USD</string>
<string name="EUR">EUR</string>
<string name="SYP">SYP</string>
<string name="LL">  LBP</string>
<string name="egp">EGP</string>
<string name="QAR">QAR</string>
<string name="AED">AED</string>
<string name="SAR">SAR</string>
<string name="IQD">IQD</string>
<string name="JOD"> JOD</string>
<string name="YER">YER</string>
<string name="LYD">LYD</string>
<string name="SDG">SDG</string>
<string name="MAD"> MAD</string>
<string name="TND"> TND</string>
<string name="KWD">KWD</string>
<string name="dzd">DZD</string>
<string name="MRO">MRO</string>
<string name="BHD"> BHD</string>
<string name="OMR"> OMR</string>
<string name="SOS">SOS</string>
<string name="FDJ">FDJ</string>

<string name="GBP">GBP</string>
<string name="TRY">TRY</string>
<string name="RUB">RUB</string>
<string name="JPY">JPY</string>

<string name="AUD">AUD</string>


<string-array name="items">
    <item>@string/Items</item>
    <item>@string/KG</item>
    <item>@string/Boxes</item>
    <item>@string/Pieces</item>
    <item>@string/Liter</item>
    <item>@string/Meter</item>
    <item>@string/Inches</item>
    <item>@string/Tons</item>
</string-array>
<string name="Items">Items</string>
<string name="KG">KG</string>
<string name="Pieces">Pieces</string>
<string name="Liter">Liter</string>
<string name="Meter">Meter</string>
<string name="Boxes">Boxes</string>
<string name="Inches">Inches</string>
<string name="Tons">Tons</string>

<string name="action_settings">Settings</string>

<string name="about_repoReview">Repo is an inventory application that helps the user with keeping track of their repository.
    It functions as a register to easily keep track of the products present in the repo, as well as their purchasing price,
    wholesale price and quantity. It helps the user calculate the total profit and profit per piece in a seamless way.
    It also shows the number of items remaining in the inventory. What makes Repo stand out is the simplicity in use.
    It saves time and efforts, and ensures precision in calculations.</string>


<string name="view_repository"> View Inventory Checklist </string>
<string name="edit_product_name"> Edit product name</string>
<string name="delete_product">Delete product card</string>
<string name="are_u_sure">Do you want to delete this product card permanently?</string>
<string name="options">Options</string>
<string name="yes">Yes</string>
<string name="No">No</string>
<string name="cancel">Cancel</string>
<string name="product_card_deleted">Product card is deleted </string>
<string name="product_name_hasbeenUpdated">Product name is updated </string>
<string name="product_name_isAlreadyExisted">Product name is already existed</string>
<string name="product_nameisalreadyExistedqst">You already have the same Product name in your list do you want to add another product with the same name?</string>
<string name="name_cannotBeEmpty">Column Name cannot be empty!</string>
<string name="qty_cannotBeEmpty">Column Quantity cannot be empty!</string>

<string name="product_Name">Product Name</string>
<string name="id">ID</string>
<string name="last_added_qty">Last In Quantity </string>
<string name="entry_date">Input Date</string>
<string name="last_out_qty">Last Out Quantity</string>
<string name="total_qty">Total Quantity</string>
<string name="last_updated_date">Last Updated Date</string>
<string name="retail_price">Retail Price</string>
<string name="wholesale_price">Wholesale Price</string>
<string name="retail_profit">Retail Profit</string>
<string name="wholesale_profit">Wholesale Profit</string>
<string name="total_retail_profit">Total Retail Profit</string>
<string name="total_wholesale_profit">Total Wholesale Profit</string>
<string name="purchasing_price">Purchasing Price</string>
<string name="total_purchase_price">Total Purchasing Price</string>
<string name="num_unitsInBox">Number of Units in a Box</string>
<string name="retail_price_perUnit">Retail Price per Unit</string>
<string name="wholesale_price_perUnit">WholeSale Price per Unit</string>
<string name="total_units">Total Units</string>
<string name="date_pattern">yyyy/MM/dd hh:mm:ss a</string>
<string name="In">In</string>
<string name="Out">Out</string>
<string name="isUpdated">Updated as an Output from the List</string>
<string name="addedSuccessfully">Added Successfully</string>
<string name="iUpdatedIn"> Updated</string>



<string name="enter_product_name">Enter product name</string>
<string name="enter_product_qty">Enter quantity</string>
<string name="number_units_inBox">Enter number of Units in a box</string>
<string name="retail_price_perunit">Retail price per unit</string>
<string name="wholesale_price_per_unit">Wholesale price per unit</string>
<string name="retail_price_perProduct">Retail price for product</string>
<string name="wholesale_price_perproduct">Wholesale price for product</string>
<string name="purchasing_priceofProduct">Purchasing price</string>
<string name="date_entry">date</string>
<string name="submit">Confirm</string>
<string name="isnotExisted">is not existed in your Repository</string>
<string name="the_qty_of">This quantity of </string>
<string name="this_product">This product</string>

<string name="out_by_box">Out by Box</string>
<string name="out_by_unit">Out by Unit</string>
<string name="retail_out">Retail out</string>
<string name="wholesale_out">Wholesale out</string>
<string name="date_out">Date</string>
 <string name="clear_all_list">Clear all list</string>
<string name="sortBy">Sort by</string>
<string name="Id">ID</string>
<string name="date">Entry Date</string>
<string name="lastupdaate">Last updated</string>
<string name="name">Name</string>
<string name="exit_repo">Exit Repo</string>
<string name="update">Update</string>
<string name="delete_all">Do you want to clear all of your list?</string>
<string name="your_list_is_cleared">The List has been Deleted</string>

<?xml version="1.0" encoding="utf-8"?>

<string name="app_name">ريبو</string>
<string name="newInput">إدخال جديد</string>
<string name="newOutput">إخراج جديد</string>
<string name="repository">المستودع</string>
<string name="aboutRepo">عن ريبو</string>
<string name="action_settings">الضبط</string>
<string name="view_repository">رؤية المستودع</string>
<string name="edit_product_name">تعديل إسم المنتج</string>
<string name="delete_product">حذف بطاقة المنتج</string>
<string name="are_u_sure">هل تريد حذف بطاقة هذا المنتج نهائيا</string>
<string name="options">خيارات</string>
<string name="yes">أجل</string>
<string name="No">لا</string>
<string name="cancel">إلغاء</string>
<string name="product_card_deleted">تم حذف هذه البطاقة</string>
<string name="product_name_hasbeenUpdated">تم تعديل إسم المنتج</string>
<string name="product_name_isAlreadyExisted">إسم المنتج موجود ضمن قائمة المستودع</string>
<string name="product_nameisalreadyExistedqst">إسم المنتج موجود مسبقا ضمن قائمة المستودع هل ترغب بإضافة منتج آخر بنفس الإسم إلى المستودع</string>
<string name="name_cannotBeEmpty">خانة الإسم لا يمكن أن تكون فارغة</string>
<string name="qty_cannotBeEmpty">"خانة الكمية لا يمكن أن تكون فارغة "</string>
<string name="product_Name">إسم المنتج</string>
<string name="id">رقم التعريف</string>
<string name="last_added_qty">آخر كمية تم إدخالها</string>
<string name="entry_date">تاريخ الإدخال</string>
<string name="last_out_qty">آخر كمية تم إخراجها</string>
<string name="total_qty">الكمية الإجمالية</string>
<string name="last_updated_date">آخر تحديث</string>
<string name="retail_price">سعر التجزئة</string>
<string name="wholesale_price">سعر الجملة</string>
<string name="retail_profit">ربح التجزئة</string>
<string name="wholesale_profit">ربح الجملة</string>
<string name="total_retail_profit">ربح التجزئة الإجمالي</string>
<string name="total_wholesale_profit">ربح الجملة الإجمالي</string>
<string name="purchasing_price">سعر الشراء</string>
<string name="total_purchase_price">سعر الشراء الإجمالي</string>
<string name="num_unitsInBox">"عدد القطع في الصندوق "</string>
<string name="retail_price_perUnit">سعر التجزئة للقطعة</string>
<string name="wholesale_price_perUnit">سعر الجملة للقطعة</string>
<string name="total_units">"العدد الإجمالي للقطع "</string>

<string name="addedSuccessfully">تمت الإضافة بنجاح</string>

<string name="enter_product_name">أدخل إسم المنتج</string>
<string name="enter_product_qty">أدخل الكمية</string>
<string name="number_units_inBox">أدخل عدد القطع في الصندوق</string>
<string name="retail_price_perunit">سعر التجزئة للقطعة</string>
<string name="wholesale_price_per_unit">سعر الجملة للقطعة</string>
<string name="retail_price_perProduct">سعر التجزئة للمنتج</string>
<string name="wholesale_price_perproduct">سعر الجملة للمنتج</string>
<string name="purchasing_priceofProduct">سعر الشراء</string>
<string name="date_entry">التاريخ</string>
<string name="submit">تثبيت</string>
<string name="out_by_box">إخراج بالصندوق</string>
<string name="out_by_unit">"إخراج بالقطعة "</string>
<string name="retail_out">إخراج بالتجزئة</string>
<string name="wholesale_out">إخراج بالجملة</string>
<string name="date_out">التاريخ</string>
<string name="clear_all_list">حذف كل القائمة</string>
<string name="sortBy">تصنيف حسب</string>
<string name="Id">رقم التعريف</string>
<string name="date">تاريخ الإدخال</string>
<string name="lastupdaate">آخر تحديث</string>
<string name="name">الإسم</string>
<string name="exit_repo">"خروج "</string>
<string name="update">تحديث</string>
<string name="isnotExisted">غير موجودة ضمن قائمة المستودع</string>
<string name="the_qty_of">هذه الكمية</string>
<string name="this_product">هذا المنتج</string>

<string name="delete_all">هل ترغب بحذف كل القائمة؟</string>
<string name="your_list_is_cleared">تم حذف القائمة</string>
<string name="SYP">\tل.س</string>
<string name="LL">\tل.ل</string>
<string name="egp">\tج.م</string>
<string name="QAR">\tر.ق</string>
<string name="AED">\tد.إ</string>
<string name="SAR">\tر.س</string>
<string name="IQD">\tد.ع</string>
<string name="JOD">\tد.ا</string>
<string name="YER">\tر.ي</string>
<string name="LYD">\tد.ل</string>
<string name="SDG">ج.س</string>
<string name="MAD">\tد.م</string>
<string name="TND">د.ت</string>
<string name="KWD">د.ك</string>
<string name="dzd">\tد.ج</string>
<string name="MRO">\tأ.م</string>
<string name="BHD">د.ب</string>
<string name="OMR">ر.ع</string>
<string name="SOS">ش.ص</string>
<string name="FDJ">ف.ج</string>

<string name="GBP">جنيه إسترليني £</string>

<string name="TRY">\tليرة تركية ₺</string>
<string name="RUB">روبل روسي \t₽</string>
<string name="JPY">ين ¥</string>
<string name="AUD">دولار أسترالي \t$</string>
<string name="about_repoReview">ريبو هو تطبيق للجرد بحيث يساعد المستخدم على أن يبقى محافظ على تتبع مخزنه و بضاعته، يعمل التطبيق على شكل قائمة لتسهيل تتبع المنتجات المسجلة في تطبيق ريبو وأيضا يسجل سعر الشراء، سعر الجملة، سعر التجزئة و الكمية الإجمالية.  يساعد تطبيق ريبو مستخدميه على حساب ربحه الإجمالي و الربح في الوحدة الواحدة بطريقة سلسة، بالإضافة إلى أنه يظهر عدد العناصر المتبقية في المستودع. سلاسة وبساطة استخدامه هو ما يجعل من تطبيق ريبو مميز فهو يوفر الوقت والجهد و يضمن لك دقة عالية في الحسابات.</string>
<string name="isUpdated">تم الإخراج من القائمة</string>
<string name="iUpdatedIn">تم التحديث</string>
<string name="db_name">Repository_ar</string>

<string name="table_name">repository</string>

<string name="KG">كغ</string>
<string name="Pieces">قطعة</string>
<string name="Liter">لتر</string>
<string name="Meter">متر</string>
<string name="Boxes">صندوق</string>
<string name="Inches">إنش</string>
<string name="Tons">طن</string>
<string name="USD">دولار أمريكي $</string>
<string name="EUR">يورو €</string>
<string name="In">إدخال</string>
<string name="Out">إخراج</string>
<string name="Items">مادة</string>

the adapter code

 textViewname.setText(context.getString(R.string.product_Name)+" " + repo.getName());

textViewquantity.setText(context.getString(R.string.last_added_qty)+" " + repo.getQuantity() + " "+ context.getResources().getString(mdatabase. getIds(repo.getItemsType())));
java
android
sqlite
localization
adapter
asked on Stack Overflow Dec 22, 2019 by hoabouseif • edited Dec 24, 2019 by HP371

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0