From 8a018903f020479ee12cc7e0811eec1918f0f911 Mon Sep 17 00:00:00 2001 From: leca Date: Sat, 19 Oct 2024 19:25:39 +0300 Subject: [PATCH] translated app to russian --- .../barcodescannerforemployees/Parser.kt | 5 -- .../activities/AddAbstractProductActivity.kt | 14 ++-- .../activities/AddProductActivity.kt | 18 ++--- .../activities/MainActivity.kt | 18 ++--- .../fragments/CategoriesFragment.kt | 2 +- .../fragments/ShelfFragment.kt | 18 ++--- .../fragments/StorageFragment.kt | 12 ++- .../views/ProductView.kt | 2 +- .../layout/fragment_add_abstract_product.xml | 2 +- .../main/res/layout/fragment_add_product.xml | 12 +-- app/src/main/res/layout/fragment_shelf.xml | 3 +- app/src/main/res/layout/fragment_storage.xml | 2 +- app/src/main/res/values-ru/strings.xml | 80 +++++++++++++++++++ app/src/main/res/values/strings.xml | 55 +++++++++++-- 14 files changed, 178 insertions(+), 65 deletions(-) create mode 100644 app/src/main/res/values-ru/strings.xml diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Parser.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Parser.kt index 4a668c7..e046688 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Parser.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Parser.kt @@ -1,6 +1,5 @@ package org.foxarmy.barcodescannerforemployees -import android.util.Log import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct class Parser constructor() { @@ -14,9 +13,6 @@ class Parser constructor() { val found = foundByRegex.groupValues[0] text = text.replace(found, "") netWeight = stripNetWeight(found) -// when (found.lowercase().strip()) { -// "кг" -> netWeight *= 1000 -// "мл" -> netWeight /= 1000 // } return Triple(text, netWeight, found) } @@ -46,7 +42,6 @@ class Parser constructor() { else -> { -1 } } - Log.d("QWERTYUIOP", "Unit: ${strippedUnit}, number: ${unitNumber}") return AbstractProduct(0, "", name, netWeight, "", 0, unitNumber) } diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt index 6bbbae3..a9e4000 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt @@ -103,21 +103,21 @@ class AddAbstractProductActivity : AppCompatActivity() { val productName = productNameText.text.toString() val netWeight = netWeightText.text if (abstractProduct == null && (!this::pictureFile.isInitialized || !pictureFile.exists())) { - Toast.makeText(this, "Please, make a picture of a product!", Toast.LENGTH_SHORT).show() + Toast.makeText(this, getString(R.string.product_picture_request), Toast.LENGTH_SHORT).show() return@setOnClickListener } if (barcode == "") { - Toast.makeText(this, "Please, scan barcode on a product", Toast.LENGTH_SHORT).show() + Toast.makeText(this, getString(R.string.product_barcode_request), Toast.LENGTH_SHORT).show() return@setOnClickListener } if (productName == "") { - Toast.makeText(this, "Please, write a name of a product!", Toast.LENGTH_SHORT).show() + Toast.makeText(this, getString(R.string.product_name_request), Toast.LENGTH_SHORT).show() return@setOnClickListener } if (netWeight.toString() == "" || netWeight.toString().toDoubleOrNull() == null) { - Toast.makeText(this, "Please, write a valid net weight of a product!", Toast.LENGTH_SHORT).show() + Toast.makeText(this, getString(R.string.product_net_weight_request), Toast.LENGTH_SHORT).show() } val db = DBStorageController(this).writableDatabase @@ -294,14 +294,14 @@ class AddAbstractProductActivity : AppCompatActivity() { getPicture() } } else { - Toast.makeText(this, "I need permission in order to take a picture", Toast.LENGTH_LONG).show() + Toast.makeText(this, getString(R.string.camera_permission_for_picture_request), Toast.LENGTH_LONG).show() } } private val scanLauncher = registerForActivityResult(ScanContract()) { result: ScanIntentResult -> run { if (result.contents == null) { - Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show() + Toast.makeText(this, getString(R.string.cancelled), Toast.LENGTH_SHORT).show() } else { scanningBarcode = false val scannedBarcode = result.contents @@ -314,7 +314,7 @@ class AddAbstractProductActivity : AppCompatActivity() { private fun prepareBarcodeScanner() { val options = ScanOptions() options.setDesiredBarcodeFormats(ScanOptions.EAN_13) - options.setPrompt("Scan barcode of a product") + options.setPrompt(getString(R.string.scan_barcode_of_a_product)) options.setCameraId(0) options.setBeepEnabled(false) options.setBarcodeImageEnabled(true) diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt index 1820d74..773f0ac 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt @@ -131,11 +131,11 @@ class AddProductActivity : AppCompatActivity() { saveProductButton.setOnClickListener { if (expiryDateOverShelfLife == null) { - Toast.makeText(this, "Please, choose and fill in shelf life or expiry date.", Toast.LENGTH_SHORT).show() + Toast.makeText(this, getString(R.string.shell_life_or_expiry_date_request), Toast.LENGTH_SHORT).show() return@setOnClickListener } if (product!!.dateOfProduction == 0.toLong()) { - Toast.makeText(this, "Please, choose date of production.", Toast.LENGTH_SHORT).show() + Toast.makeText(this, getString(R.string.date_of_production_request), Toast.LENGTH_SHORT).show() return@setOnClickListener } @@ -145,13 +145,13 @@ class AddProductActivity : AppCompatActivity() { } } else { if (product!!.dateOfExpiry == 0.toLong()) { - Toast.makeText(this, "Please, choose date of expiry.", Toast.LENGTH_SHORT).show() + Toast.makeText(this, getString(R.string.expiry_date_request), Toast.LENGTH_SHORT).show() return@setOnClickListener } } if (product!!.amount == 0) { - Toast.makeText(this, "Please, specify an amount of product.", Toast.LENGTH_SHORT).show() + Toast.makeText(this, getString(R.string.product_amount_request), Toast.LENGTH_SHORT).show() return@setOnClickListener } @@ -180,10 +180,10 @@ class AddProductActivity : AppCompatActivity() { shelfLifeTextView.visibility = View.VISIBLE } val dateOfProductionParsed = SimpleDateFormat("dd.MM.yyyy").format(Date(product!!.dateOfProduction * 1000)) - findViewById(R.id.dateOfProductionTextView).text = "Date of production: $dateOfProductionParsed" + findViewById(R.id.dateOfProductionTextView).text = "${getString(R.string.date_of_production)}: $dateOfProductionParsed" val expiryDateParsed = SimpleDateFormat("dd.MM.yyyy").format(Date(product!!.dateOfExpiry * 1000)) - expiryDateTextView.text = "Expiry date: $expiryDateParsed" + expiryDateTextView.text = "${getString(R.string.expiry_date)}: $expiryDateParsed" if (amountTextEdit.text.toString() == "") { amountTextEdit.setText(product!!.amount.toString()) @@ -219,14 +219,14 @@ class AddProductActivity : AppCompatActivity() { if (isGranted) { prepareBarcodeScanner() } else { - Toast.makeText(this, "I need permission in order to take a picture", Toast.LENGTH_LONG).show() + Toast.makeText(this, getString(R.string.camera_permission_for_scanning_request), Toast.LENGTH_LONG).show() } } private val scanLauncher = registerForActivityResult(ScanContract()) { result: ScanIntentResult -> run { if (result.contents == null) { - Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show() + Toast.makeText(this, getString(R.string.cancelled), Toast.LENGTH_SHORT).show() } else { val scannedBarcode = result.contents abstractProduct = DBStorageController(this).findAbstractProductByBarcode(DBStorageController(this).readableDatabase, scannedBarcode) @@ -239,7 +239,7 @@ class AddProductActivity : AppCompatActivity() { private fun prepareBarcodeScanner() { val options = ScanOptions() options.setDesiredBarcodeFormats(ScanOptions.EAN_13) - options.setPrompt("Scan barcode of a product") + options.setPrompt(getString(R.string.scan_barcode_of_a_product)) options.setCameraId(0) options.setBeepEnabled(false) options.setBarcodeImageEnabled(true) diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt index 2c8d336..ae826cc 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt @@ -69,9 +69,9 @@ class MainActivity : AppCompatActivity() { private fun setupViewPager(viewpager: ViewPager) { adapter = ViewPagerAdapter(supportFragmentManager) - adapter.addFragment(CategoriesFragment(), "Categories") - adapter.addFragment(StorageFragment(), "Storage") - adapter.addFragment(ShelfFragment(), "Shelf") + adapter.addFragment(CategoriesFragment(), getString(R.string.categories_title)) + adapter.addFragment(StorageFragment(), getString(R.string.storage_title)) + adapter.addFragment(ShelfFragment(), getString(R.string.shelf_title)) //TODO: settings fragments // setting adapter to view pager. @@ -99,24 +99,24 @@ class MainActivity : AppCompatActivity() { when (fragment::class.simpleName.toString()) { "StorageFragment" -> { AlertDialog.Builder(this) - .setMessage("Deleting an abstract product will also delete ALL the products, that belong to it. Do you want to proceed?") - .setPositiveButton("Yes") { _: DialogInterface, _: Int -> + .setMessage(getString(R.string.deleting_abstract_product_warning)) + .setPositiveButton(getString(R.string.yes)) { _: DialogInterface, _: Int -> val storageFragment = fragment as StorageFragment storageFragment.removeSelected() } - .setNegativeButton("No") { _: DialogInterface, _: Int -> + .setNegativeButton(getString(R.string.no)) { _: DialogInterface, _: Int -> }.show() } "CategoriesFragment" -> { AlertDialog.Builder(this) - .setMessage("Deleting a category will also delete ALL the products, that belong to that category. Do you want to proceed?") - .setPositiveButton("Yes") { _: DialogInterface, _: Int -> + .setMessage(getString(R.string.deleting_category_warning)) + .setPositiveButton(getString(R.string.yes)) { _: DialogInterface, _: Int -> val categoriesFragment = fragment as CategoriesFragment categoriesFragment.removeSelected() } - .setNegativeButton("No") { _: DialogInterface, _: Int -> + .setNegativeButton(getString(R.string.no)) { _: DialogInterface, _: Int -> }.show() } diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/CategoriesFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/CategoriesFragment.kt index a2db862..051a8b9 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/CategoriesFragment.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/CategoriesFragment.kt @@ -45,7 +45,7 @@ class CategoriesFragment : Fragment() { } if (!deleted) { - Toast.makeText(requireContext(), "Nothing to delete", Toast.LENGTH_SHORT).show() + Toast.makeText(requireContext(), getString(R.string.nothing_to_delete), Toast.LENGTH_SHORT).show() } updateContent() } diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ShelfFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ShelfFragment.kt index c908d04..8181905 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ShelfFragment.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ShelfFragment.kt @@ -69,13 +69,13 @@ class ShelfFragment : Fragment() { } if (!updated) { - Toast.makeText(requireContext(), "Nothing to update", Toast.LENGTH_SHORT).show() + Toast.makeText(requireContext(), getString(R.string.nothing_to_update), Toast.LENGTH_SHORT).show() } updateContent() } private fun fillUpSortBySpinner() { - val sorts = mutableListOf("Name", "Category", "Freshness", "Date of production", "Date of expiry") + val sorts = resources.getStringArray(R.array.product_sort_types) val arrayAdapter = ArrayAdapter(requireContext(), androidx.appcompat.R.layout.support_simple_spinner_dropdown_item, sorts) @@ -109,13 +109,13 @@ class ShelfFragment : Fragment() { var orderBy: String = "" - when (binding.spinner.selectedItem) { - "Name" -> { + when (binding.spinner.selectedItemPosition) { + 0 -> { orderBy = "(SELECT ${AbstractProductContract.AbstractProductEntry.PRODUCT_NAME} FROM ${AbstractProductContract.AbstractProductEntry.TABLE_NAME} WHERE ${BaseColumns._ID} = ${ProductContract.ProductEntry.ABSTRACT_PRODUCT_ID}) ASC" } - "Category" -> { + 1 -> { orderBy = "(SELECT ${AbstractProductContract.AbstractProductEntry.CATEGORY} FROM ${AbstractProductContract.AbstractProductEntry.TABLE_NAME} WHERE ${BaseColumns._ID} = ${ProductContract.ProductEntry.ABSTRACT_PRODUCT_ID}) ASC" } @@ -126,11 +126,11 @@ class ShelfFragment : Fragment() { // "(SELECT ( (julianday(${ProductContract.ProductEntry.EXPIRY_DATE}) - julianday('now', 'localtime')) / (julianday(${ProductContract.ProductEntry.EXPIRY_DATE}) - julianday(${ProductContract.ProductEntry.DATE_OF_PRODUCTION})) )) ASC" // } - "Date of production" -> { + 3 -> { orderBy = "${ProductContract.ProductEntry.DATE_OF_PRODUCTION} ASC" } - "Date of expiry" -> { + 4 -> { orderBy = "${ProductContract.ProductEntry.EXPIRY_DATE} ASC" } } @@ -151,7 +151,7 @@ class ShelfFragment : Fragment() { val product = Product(productId, abstractProductId, amount, dateOfProduction, dateOfExpiry) - if (binding.spinner.selectedItem == "Freshness") { + if (binding.spinner.selectedItemPosition == 2) { //freshness products.add(product) } else { val productView = ProductView( @@ -200,7 +200,7 @@ class ShelfFragment : Fragment() { if (!deleted) { activity!!.runOnUiThread { - Toast.makeText(requireContext(), "Nothing to delete", Toast.LENGTH_SHORT).show() + Toast.makeText(requireContext(), getString(R.string.nothing_to_delete), Toast.LENGTH_SHORT).show() } } updateContent() diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt index 24d688e..cf64f3b 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt @@ -3,7 +3,6 @@ package org.foxarmy.barcodescannerforemployees.fragments import android.content.Intent import android.os.Bundle import android.provider.BaseColumns -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -56,8 +55,7 @@ class StorageFragment : Fragment() { } private fun fillUpSortBySpinner() { - val sorts = mutableListOf("Name", "Category") - + val sorts = resources.getStringArray(R.array.abstract_product_sort_types) val arrayAdapter = ArrayAdapter(requireContext(), androidx.appcompat.R.layout.support_simple_spinner_dropdown_item, sorts) arrayAdapter.setDropDownViewResource(androidx.appcompat.R.layout.support_simple_spinner_dropdown_item) binding.spinner.adapter = arrayAdapter @@ -81,7 +79,7 @@ class StorageFragment : Fragment() { if (!deleted) { activity!!.runOnUiThread { - Toast.makeText(requireContext(), "Nothing to delete", Toast.LENGTH_SHORT).show() + Toast.makeText(requireContext(), getString(R.string.nothing_to_delete), Toast.LENGTH_SHORT).show() } } updateContent() @@ -121,11 +119,11 @@ class StorageFragment : Fragment() { ) var orderBy: String = "" - when(binding.spinner.selectedItem) { - "Name" -> { + when(binding.spinner.selectedItemPosition) { + 0 -> { orderBy = "${AbstractProductContract.AbstractProductEntry.PRODUCT_NAME} ASC" } - "Category" -> { + 1 -> { orderBy = "${AbstractProductContract.AbstractProductEntry.CATEGORY} ASC" } } diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt index 936784e..612208b 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt @@ -104,7 +104,7 @@ class ProductView: LinearLayout { productLifeSpan.text = "${SimpleDateFormat("dd.MM.yyyy").format(Date(product.dateOfProduction*1000))}-${SimpleDateFormat("dd.MM.yyyy").format(Date(product.dateOfExpiry*1000))}" productFreshnessTextView.text = if (product.freshness == Double.NEGATIVE_INFINITY || product.freshness == Double.POSITIVE_INFINITY || product.freshness < 0) { - "Expired" + context.getString(R.string.expired) } else { "${DecimalFormat("#.#").format(product.freshness*100)}%" } diff --git a/app/src/main/res/layout/fragment_add_abstract_product.xml b/app/src/main/res/layout/fragment_add_abstract_product.xml index 5fe0b8c..c97a92d 100644 --- a/app/src/main/res/layout/fragment_add_abstract_product.xml +++ b/app/src/main/res/layout/fragment_add_abstract_product.xml @@ -37,7 +37,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toTopOf="@+id/netWeight" app:layout_constraintHorizontal_bias="0.5" - android:visibility="visible" android:hint="@string/product_name_label" android:textColorHint="#737373" + android:visibility="visible" android:hint="@string/productName" android:textColorHint="#737373" android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/barcodeTextEdit"/>